Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Help Deleting Old Backups
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Off the Wall
View previous topic :: View next topic  
Author Message
Nick W
l33t
l33t


Joined: 07 Dec 2003
Posts: 684

PostPosted: Thu Jul 07, 2005 4:40 pm    Post subject: Help Deleting Old Backups Reply with quote

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
View user's profile Send private message
BlackEdder
Advocate
Advocate


Joined: 26 Apr 2004
Posts: 2586
Location: Dutch enclave in Egham, UK

PostPosted: Thu Jul 07, 2005 4:50 pm    Post subject: Reply with quote

Code:
find 20* -cmin +300 | xargs rm
Back to top
View user's profile Send private message
Anior
Guru
Guru


Joined: 17 Apr 2003
Posts: 317
Location: European Union (Stockholm / Sweden)

PostPosted: Thu Jul 07, 2005 4:53 pm    Post subject: Reply with quote

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
View user's profile Send private message
BlackEdder
Advocate
Advocate


Joined: 26 Apr 2004
Posts: 2586
Location: Dutch enclave in Egham, UK

PostPosted: Thu Jul 07, 2005 4:55 pm    Post subject: Reply with quote

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
View user's profile Send private message
Anior
Guru
Guru


Joined: 17 Apr 2003
Posts: 317
Location: European Union (Stockholm / Sweden)

PostPosted: Thu Jul 07, 2005 4:57 pm    Post subject: Reply with quote

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
View user's profile Send private message
Nick W
l33t
l33t


Joined: 07 Dec 2003
Posts: 684

PostPosted: Thu Jul 07, 2005 7:19 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Off the Wall All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum