| View previous topic :: View next topic |
| Author |
Message |
Nick W l33t


Joined: 07 Dec 2003 Posts: 684
|
Posted: Thu Jul 07, 2005 4:40 pm Post subject: Help Deleting Old Backups |
|
|
Hi everyone,
I have cron job backing up a mysql db once an hour, and would like to delete backups over 5hrs old on the same cronjob.
The files look like this:
| Code: |
20050531082008.sql.bz2 20050705080119.sql.bz2 20050707111000.sql.bz2
20050601080228.sql.bz2 20050707091732.sql.bz2 20050707121000.sql.bz2
|
Can somebody tell me, or point me to some function/command that will help me delete the older backups regulary?
thanks very much! |
|
| Back to top |
|
 |
BlackEdder Advocate


Joined: 26 Apr 2004 Posts: 2586 Location: Dutch enclave in Egham, UK
|
Posted: Thu Jul 07, 2005 4:50 pm Post subject: |
|
|
| Code: | | find 20* -cmin +300 | xargs rm |
|
|
| Back to top |
|
 |
Anior Guru


Joined: 17 Apr 2003 Posts: 317 Location: European Union (Stockholm / Sweden)
|
Posted: Thu Jul 07, 2005 4:53 pm Post subject: |
|
|
Gnu: | Code: | | find /var/backups -ctime +150 -exec rm -f {} \; |
Posix: | Code: | | find /var/backups -ctime +150 -print|xargs /bin/rm -f |
Uses 150 days instead of 5 months but it should be close enough.
Last edited by Anior on Thu Jul 07, 2005 4:56 pm; edited 1 time in total |
|
| Back to top |
|
 |
BlackEdder Advocate


Joined: 26 Apr 2004 Posts: 2586 Location: Dutch enclave in Egham, UK
|
Posted: Thu Jul 07, 2005 4:55 pm Post subject: |
|
|
| Anior wrote: | | Uses 150 days instead of 5 months but it should be close enough. |
He asked for 5 hrs not months, and I'm pretty sure you need a +150 else it will only delete those files precisely 150 days old. |
|
| Back to top |
|
 |
Anior Guru


Joined: 17 Apr 2003 Posts: 317 Location: European Union (Stockholm / Sweden)
|
Posted: Thu Jul 07, 2005 4:57 pm Post subject: |
|
|
| BlackEdder wrote: | | Anior wrote: | | Uses 150 days instead of 5 months but it should be close enough. |
He asked for 5 hrs not months, and I'm pretty sure you need a +150 else it will only delete those files precisely 150 days old. |
Just edited it, but thanks.
And yea, my bad misread the time. |
|
| Back to top |
|
 |
Nick W l33t


Joined: 07 Dec 2003 Posts: 684
|
Posted: Thu Jul 07, 2005 7:19 pm Post subject: |
|
|
oooh, thankyou!
I did ask on my own site aswell, though didn't expect anyone to reply as it's not really a linux site. I got this answer
| Code: |
find "/home/backups/" -ctime +1 -name "*.bak" -exec rm '{}' \\;
|
Thanks again, i'll play around with it, check the man pages and sort it  |
|
| Back to top |
|
 |
|