I'm looking for a tool (for Linux) that will prune my backup files, not like the standard logrotate that completely deletes them after defined number of rotations, but where the files are basically kept permanently, except they are pruned as they get older and older. For example:

  • for the first month I want to keep every single daily backup file
  • after that I only want to keep a weekly backup for the next 6 months
  • after that I only want to keep a monthly backup for another 6 months
  • after that I only want to keep a quarterly backup

Does a tool to do such a time-based cleanup of files exist?

It could either be looking at a date in the file name, or the timestamp of the file (not ideal though).

  • This seems like a pretty basic thing for any backup software to handle transparently. How are you generating these backups?
    – GregL
    Feb 3 '17 at 13:39

There isn't such a tool I know of, usually this is inculded in your backup software. What backup tool do you use?

I would recommend rsnapshot This can be configured to do these smart things you ask for, and keeps backup size small by extensive use of hardlinks.

If however you have your own cronjobs/system for creating backups, you could just create a few more cronjobs.

  • make backups to a 'daily folder'
  • have a weekly cronjob that moves files older then 30days from your monthly folder to your 'weekly folder' find /path/to/daily -maxdepth 1 -mtime +30 -type f -exec mv "{}" /path/to/weekly/ \;

    because the below cronjob will remove older files this will only be one day's worth of backup files.

  • have a daily cronjob that removes files older then 30 days from your daily folder (make sure it runs after the weekly cron above) find /path/to/daily/* -mtime +30 -exec rm {} \;

repeat for weekly to monthly and monthly to quarterly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.