I'd like to set up this database backup routine with cron:
- Every month on the first, do a full backup
- Every Sunday of the week, do an incremental backup - unless it's the 1st
- Every day of the week, do an incremental delta backup - unless it's the 1st, or Sunday
The database is DB2, should anyone wonder. "Full" means full, "incremental" means cumulative incremental, and "incremental delta" means "non-cumulative incremental". Worst case restore scenario would be "full + incremental + 6 deltas".
This is what I tried:
# monthly 0 0 1 * * ("do full backup") # weekly 0 0 2-31 * 0 ("do incremental backup") # daily 0 0 2-31 * 1-6 ("do incremental delta backup")
... hoping that the second line would mean "do backup on Sunday, but only if the date is between the 2nd and the 31st". I turns out cron does not AND its time arguments, but ORs them. So midnight between Tuesday the 18th and Wednesday the 19th, both a daily and a weekly backup was set in motion, regardless it not being Sunday. Incidentally, the daily "came first" and blocked the weekly.
Now, I could fiddle with the timing so that during the course of the day, the monthly backup always starts before the weekly, starts before the daily (e.g. at 00.01, 00.02 and 00.03), thus making use of the "blocking" phenomenon to achieve my goal. That is ugly, though, and every so often I would have to deal with error output that isn't really an error (a blocked backup).
Also, I could base my scheme solely on day-of-months. But a full backup taxes host ressources hard, so my users would really like the full backup to run in the weekend.
Any suggestions that doesn't require scripting? I'd like to keep the setup very basic for ease of future use and understanding. Moreover, different user groups will want sligthly different backup policies, and I don't like scripting small differences.