]> git.sur5r.net Git - bacula/bacula/blob - bacula/examples/backup-every-other-week.txt
Update doc
[bacula/bacula] / bacula / examples / backup-every-other-week.txt
1
2 From bacula-users-admin@lists.sourceforge.net Wed Aug 13 19:22:21 2003
3 From: Robert L Mathews <lists@tigertech.com>
4 To: <bacula-users@lists.sourceforge.net>
5 Content-Type: text/plain; charset="US-ASCII"
6 Message-Id: <20030813170422.E48403FC65F@fry.tigertech.net>
7 Subject: [Bacula-users] Making Backups Run Every Other Week
8 Sender: bacula-users-admin@lists.sourceforge.net
9 Date: Wed, 13 Aug 2003 10:04:23 -0700
10
11 In case anyone is interested, here's a tip I came up with.
12
13 My backup policy is such that I need backups to run every other week. I 
14 have two separate "offsite" tape pools, and a backup is made to each of 
15 them on alternating weeks.
16
17 Bacula's scheduler currently doesn't handle "every two weeks", and using 
18 something like "the first and third weeks for backup A, and the second 
19 and fourth weeks for backup B" means there will be no backup done on the 
20 fifth week if the month contains one. Scheduling a backup for the fifth 
21 week doesn't help; it means that the same backup would sometimes run 
22 twice in a row, which ruins the alternating week scheme.
23
24 I first thought of poking around the code to make the scheduler support 
25 "every two weeks", and I someday may still do so. However, I found an 
26 easier way to do this is in the meantime: with a RunBeforeJob line.
27
28 What I do is schedule both jobs to run every single week. Then the job 
29 that runs my "Offsite Backup A" has this line:
30
31   RunBeforeJob = "/etc/bacula/two_week_script 'July 6 2003'"
32
33 And the job with my "Offsite Backup B" has this one:
34
35   RunBeforeJob = "/etc/bacula/two_week_script 'July 13 2003'"
36
37 And two_week_script is the following Perl script:
38
39 ----------------
40
41 #!/usr/bin/perl -w
42
43 use strict;
44 use constant SECONDS_IN_WEEK => 86400 * 7;
45 use constant SECONDS_IN_TWO_WEEKS => SECONDS_IN_WEEK * 2;
46
47 # Calculate the elapsed seconds since the starting date,
48 # which must be in a format that /bin/date can understand
49 # Note that this relies on the GNU "%s" date extension
50 my $start_date = shift;
51 $start_date = `/bin/date -d '$start_date' +'%s'`;
52 chomp $start_date;
53 my $time_since_start_date = time - $start_date;
54
55 # Now take those seconds modulo the number of seconds in
56 # two weeks. If we're in the second half of the two week
57 # period, exit with an error to stop the Bacula job. If
58 # we're in the first half, the script will terminate normally
59 # and the Bacula job will run.
60 if ($time_since_start_date % SECONDS_IN_TWO_WEEKS
61         >= SECONDS_IN_WEEK)
62 {
63         exit 1;
64 }
65
66 ----------------
67
68 The result is that the script cancels the job that should not be run that 
69 week, while allowing the other job to continue.
70
71 This idea could be trivially changed to support running every three 
72 weeks, every two months, every prime number of days, etc.
73
74 Anyway, just a tip in case anyone else needs to schedule things in a way 
75 that the scheduler doesn't currently support. It's pretty obvious that 
76 this is the right way to do it now, but I puzzled over it for a little 
77 while before coming up with this.
78
79 -- 
80 Robert L Mathews, Tiger Technologies
81
82
83
84 -------------------------------------------------------
85 This SF.Net email sponsored by: Free pre-built ASP.NET sites including
86 Data Reports, E-commerce, Portals, and Forums are available now.
87 Download today and enter to win an XBOX or Visual Studio .NET.
88 http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
89 _______________________________________________
90 Bacula-users mailing list
91 Bacula-users@lists.sourceforge.net
92 https://lists.sourceforge.net/lists/listinfo/bacula-users