Backup strategy

 
Written By Sanjir Habib On May-9th, 2021
Figured out best is to keep a daily rotating backup for a week. And then a monthly rotating backup for a year.

For that, instead of writing complex scripts... the following cron jobs entries do.

@daily cp myfile.db /backup/myfile.db.$(date +\%a)
@monthly cp myfile.db /backup/myfile.db.$(date +\%b)

These two entries copy the the file you intend to backup renaming it as *.Sun *.Mon, *.Tue on to the backup disk, overwriting the old one with the new one each week. You don't explicitly delete any file.

Same goes for monthly backups. These are saved as *.Jan *.Feb and so on.

To figure which exact date that backup is from check the date of the file on the file system. That should do it. Appending the date to file name will require more complex book keeping on which backup file to delete for space.

But this way, it rotates by overwriting. Simple.

Also in case you weren't aware... you don't need to lookup for help for the star * values every time you enter a crontab entry. Rather use @daily @monthly @yearly @hourly @weekly as you like.

That's easier.