Shell script for Archive and remove
old files.
cd /var/spool ls -l |grep ^d |awk '{print $NF}' |while read folder # if find command support -maxdepth option # find . -maxdepth 1 -type d |while read folder do mkdir -p /backup/spool/$folder find $folder -mtime +15 -exec mv {} /backup/spool/$folder \; cd /backup/spool tar -cvzf "$folder-`date '+%Y-%m-%d'`.zip" $folder # Below commented line will backup the removing folders if needed. # mv $folder*.tar /dump_restore/spool/ cd /backup/spool/$folder/ rm* cd /var/spool done
Archiving Old files to one tar ball
cd /var/spool find . -mtime +15 -type f > /tmp/filelist tar --create --gzip --files-from /tmp/filelist --file /dump_restore/spool/repository-`date +%Y%m%d`.tar.gz find . -mtime +15 -type f -exec rm {} \;
No comments:
Post a Comment