__/ [Buck Turgidson] on Friday 04 November 2005 14:47 \__
> I have some db2 database backups in a directory. They take up a lot of
> space, so I'd like to delete all but the latest. I can't use "find" and
> "rm" because the backups aren't done on a predicatable interval.
>
> The only thing I do know is that I only want the latest one, and delete
> the rest. If there is only one in the directory, of course I don't want
> to delete it.
>
> Can any bash experts give me some ideas?
Here are some bits which I use to handle backup tasks, which roughly match
your description.
Each night the following gets run:
tar czvf /home/server2/transfer/roy/Transfer_Archives/www-`date
+%Y-%m-%d`.tar.gz /home/roy/Main/Misc/Transfer_Archives/Sites
This takes every file under /home/roy/Main/Misc/Transfer_Archives/Sites ,
creates one cohesive archive, labels it with the date and ships it to the
Storage Area Network.
Every night, the following gets invoked as well:
rm /home/server2/transfer/roy/Transfer_Archives/www-`date -d "4 day ago"
+%Y-%m-%d`.tar.gz
rm /home/server2/transfer/roy/Transfer_Archives/www-`date -d "5 day ago"
+%Y-%m-%d`.tar.gz
rm /home/server2/transfer/roy/Transfer_Archives/www-`date -d "6 day ago"
+%Y-%m-%d`.tar.gz
rm /home/server2/transfer/roy/Transfer_Archives/www-`date -d "7 day ago"
+%Y-%m-%d`.tar.gz
rm /home/server2/transfer/roy/Transfer_Archives/www-`date -d "8 day ago"
+%Y-%m-%d`.tar.gz
rm /home/server2/transfer/roy/Transfer_Archives/www-`date -d "9 day ago"
+%Y-%m-%d`.tar.gz
rm /home/server2/transfer/roy/Transfer_Archives/www-`date -d "10 day ago"
+%Y-%m-%d`.tar.gz
Assuming the computer is not switched off for a very long long period of time
(or the cron daemon broken), it will purge the trail of backups. Purged
backups will be older than 3 days so I still maintain a 'stack' of backups
and can revert things back to how they were 3 days ago (at most).
Hope it helps,
Roy
--
Roy S. Schestowitz | Anonymous posters are more frequently disregarded
http://Schestowitz.com | SuSE Linux | PGP-Key: 0x74572E8E
5:10pm up 1 day 13:08, 4 users, load average: 0.08, 0.11, 0.09
http://iuron.com - next generation of search paradigms
|
|