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.

Regards, Torsten

  • 1
    Is there any particular reason you don't want to use dedicated backup software? – voretaq7 Dec 19 '12 at 19:34
  • I actually am - We're using the built-in "db2 backup" functionality in conjunction with TSM. The reason why I am not scheduling the backup from TSM is that I am implementing a segregation of responsability. Often, my users want to kill a backup on grounds of performance. For the tables they want responsability for, I'm scheduling cron backup jobs that they can kill themselves. – LANerd Dec 21 '12 at 7:47
  • OK, I understand the motivation but I don't agree with the implementation -- Fragmenting your backups strikes me as a recipe for problems later. That said, mdpc's answer should work nicely – voretaq7 Dec 21 '12 at 20:59
  • I will keep that in mind. As of now, I'm trying to take apart a system that is hard to share responsability on. Later, maybe we will assemble it all again. – LANerd Dec 23 '12 at 19:36

How about this:

 # monthly
 0  0  1     *  *    ("do full backup") 
 # weekly or daily
 0  0  2-31  *  *    (if test `date +%u` -eq 7 then "do incremental backup" else "do incremental delta backup" ) 
| improve this answer | |
  • Nice idea, Lain! I will try that, thx :) (beauty is in simplicity ;)) Since I am new on the site, I cannot give you points, but here is a symbolic one: 1! – LANerd Dec 21 '12 at 7:48
  • I'm usually more of a fan of running a backup script and letting it do the date math, but this certainly works too. – voretaq7 Dec 21 '12 at 21:00
  • Oh, sorry - thanks to you, mdpc, I'm still learning how this site works. – LANerd Dec 23 '12 at 19:38

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.