Web Hosting Talk







View Full Version : Shell Command needed!


NightMan
06-10-2002, 10:00 AM
I have backup files with following formats:

userdata-20020604-0100.tar
userdata-20020605-0100.tar
userdata-20020606-0100.tar
userdata-20020607-0100.tar
userdata-20020608-0100.tar
userdata-20020609-0100.tar
userdata-20020610-0100.tar

using format: userdata-[date]-[time].tar

I set the backup script to do the job in cron and it all works fine.
but I wanted to keep the backups for only last 7days. so in this case, during the next backup, userdata-20020604-0100.tar to be deleted.

how do I add a command check the date and delete the oldest(7 day old) to my backup script?

Any suggestions?

magnafix
06-10-2002, 11:59 AM
do a 'man find'

Something similar to this may help:

find /path/to/backups/ -mtime 7 -exec rm -f {} \;

NightMan
06-10-2002, 04:15 PM
I already tried this but for some reason it is not working.

find $backupdir -name "userdata*.tar" -mtime +7 -exec rm "{}" ";"