1 |
On 09.01.2012 12:33, Alan McKinnon wrote: |
2 |
> On Mon, 09 Jan 2012 13:10:50 +0100 |
3 |
> Daniel Troeder <daniel@×××××××××.com> wrote: |
4 |
> |
5 |
>> Hi :) |
6 |
>> |
7 |
>> It seems I don't understand something about cron(tab). Can someone |
8 |
>> help me pls: |
9 |
>> |
10 |
>> I want to run flexbackup with the following backup plan: |
11 |
>> * monthly full |
12 |
>> * weekly diff |
13 |
>> * daily incr |
14 |
>> |
15 |
>> So I have installed sys-process/vixie-cron-4.1-r12 (and virtual/cron-0 |
16 |
>> and sys-process/cronbase-0.3.3). |
17 |
>> |
18 |
>> My crontab (created with "crontab -e") contains: |
19 |
>> |
20 |
>> 00 03 2-31 * 1-6 /usr/bin/flexbackup -set root -level incremental |
21 |
>> 00 03 2-31 * 0 /usr/bin/flexbackup -set root -level differential |
22 |
>> 00 03 1 * * /usr/bin/flexbackup -set root -level full |
23 |
>> |
24 |
>> The problem I'm facing is, that incr and diff are executed each day |
25 |
>> _both_ at the same time (which flexbackup luckily handles well). |
26 |
>> |
27 |
>> From my understanding the 2nd line (diff) should only be run on |
28 |
>> sundays, and the 1st line (inc) should not run sundays. |
29 |
>> |
30 |
>> |
31 |
>> Can someone please explain me what I'm doing wrong? |
32 |
> |
33 |
> You are combining fields 3 and 5, those two work funny. |
34 |
> |
35 |
> Unlike the other datetime specs, they are not ANDed, they are ORed. |
36 |
> |
37 |
> Taking the first one, you obviously want the cron to run at 3 am |
38 |
> between the 2nd and 31st of the month AND if the day is Mon-Sat. |
39 |
> |
40 |
> What it is doing is running at 3am every day between the 2nd and 31st |
41 |
> and also every day Mon-Sat (even if that is the 1st of the month). |
42 |
> |
43 |
> Vixie cron does not directly allow you to do what you want. It's |
44 |
> designed to run things periodically on a set schedule and doesn't do |
45 |
> "except" very well. |
46 |
> |
47 |
> A better approach would be to fire off a wrapper script every day at |
48 |
> 3am. This script will then check for date, time and day of week and |
49 |
> launch the app with the appropriate options. |
50 |
Thank you for the explanation! |
51 |
Unfortunately that it's ORd :( .... |
52 |
|
53 |
So I wrote this: |
54 |
|
55 |
### /etc/cron.daily/run_flexbackup ### |
56 |
|
57 |
#!/bin/bash |
58 |
|
59 |
DOM=$(date +%d) |
60 |
DOW=$(date +%w) |
61 |
|
62 |
function run_backup() { |
63 |
# do some stuff |
64 |
/usr/bin/flexbackup -set root -level $1 |
65 |
# do more stuff |
66 |
} |
67 |
|
68 |
if [ $DOM = 1 ]; then |
69 |
run_backup full |
70 |
else |
71 |
if [ $DOW = 0 ]; then |
72 |
run_backup differential |
73 |
else |
74 |
run_backup incremental |
75 |
fi |
76 |
fi |
77 |
|
78 |
|
79 |
Bye, |
80 |
Daniel |
81 |
|
82 |
-- |
83 |
PGP key @ http://pgpkeys.pca.dfn.de/pks/lookup?search=0xBB9D4887&op=get |
84 |
# gpg --recv-keys --keyserver hkp://subkeys.pgp.net 0xBB9D4887 |