3

I have daily database backups scp'd to a directory on a local linux machine for multiple databases. The naming format is [dbname].backup; there is no timestamp and currently the latest backup overwrites the previous.

Management wants to keep old versions of the files with a datestamp appended to the end, and apply the following policy for retention:

  • all files will be retained for 7 days
  • the first backup of the month for each database will be retained for 12 months
  • the first backup for each year will be retained indefinitely

I'm scratching my head how to write this script, so I was sorta hoping someone else had written something like this before, or perhaps there is a tool I am unaware of that can manage this sort of thing.

Anybody know of such a script or tool?

3
  • well, you need to use slots for this) Let me know the language or provide with existing script. I think I can help you.
    – Ilja
    Dec 6, 2013 at 20:12
  • I'm not sure what you mean? Dec 6, 2013 at 20:15
  • SLOTS="date -d-1week +%Y%m%d date -d-1month +%Y%m%d date -d-12month +%Y%m%d " According to these slots you will able to keep or delete you backup_20131206.sql files
    – Ilja
    Dec 6, 2013 at 20:17

1 Answer 1

3

We do this a lot at my company.

The main thing you'll probably use is "find" (man find). For instance:

find /home -type f -ctime +14 -exec rm -f {} \;

will delete all files from /home on down that have been created older than 14 days. You can further specify options for find to hone in on the files you are targeting.

Let me know if you need further information or help using find, but it will do everything you need it to.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .