2 From: Robert L Mathews <lists@tigertech.com>
3 To: <bacula-users@lists.sourceforge.net>
4 Subject: [Bacula-users] Making Backups Run Every Other Week
5 Date: Wed, 13 Aug 2003 10:04:23 -0700
7 In case anyone is interested, here's a tip I came up with.
9 My backup policy is such that I need backups to run every other week. I
10 have two separate "offsite" tape pools, and a backup is made to each of
11 them on alternating weeks.
13 Bacula's scheduler currently doesn't handle "every two weeks", and using
14 something like "the first and third weeks for backup A, and the second
15 and fourth weeks for backup B" means there will be no backup done on the
16 fifth week if the month contains one. Scheduling a backup for the fifth
17 week doesn't help; it means that the same backup would sometimes run
18 twice in a row, which ruins the alternating week scheme.
20 I first thought of poking around the code to make the scheduler support
21 "every two weeks", and I someday may still do so. However, I found an
22 easier way to do this is in the meantime: with a RunBeforeJob line.
24 What I do is schedule both jobs to run every single week. Then the job
25 that runs my "Offsite Backup A" has this line:
27 RunBeforeJob = "/etc/bacula/two_week_script 'July 6 2003'"
29 And the job with my "Offsite Backup B" has this one:
31 RunBeforeJob = "/etc/bacula/two_week_script 'July 13 2003'"
33 And two_week_script is the following Perl script:
40 use constant SECONDS_IN_WEEK => 86400 * 7;
41 use constant SECONDS_IN_TWO_WEEKS => SECONDS_IN_WEEK * 2;
43 # Calculate the elapsed seconds since the starting date,
44 # which must be in a format that /bin/date can understand
45 # Note that this relies on the GNU "%s" date extension
46 my $start_date = shift;
47 $start_date = `/bin/date -d '$start_date' +'%s'`;
49 my $time_since_start_date = time - $start_date;
51 # Now take those seconds modulo the number of seconds in
52 # two weeks. If we're in the second half of the two week
53 # period, exit with an error to stop the Bacula job. If
54 # we're in the first half, the script will terminate normally
55 # and the Bacula job will run.
56 if ($time_since_start_date % SECONDS_IN_TWO_WEEKS
64 The result is that the script cancels the job that should not be run that
65 week, while allowing the other job to continue.
67 This idea could be trivially changed to support running every three
68 weeks, every two months, every prime number of days, etc.
70 Anyway, just a tip in case anyone else needs to schedule things in a way
71 that the scheduler doesn't currently support. It's pretty obvious that
72 this is the right way to do it now, but I puzzled over it for a little
73 while before coming up with this.
76 Robert L Mathews, Tiger Technologies