On 09.01.2012 12:33, Alan McKinnon wrote:
> On Mon, 09 Jan 2012 13:10:50 +0100
> Daniel Troeder <dan...@admin-box.com> wrote:
> 
>> Hi :)
>>
>> It seems I don't understand something about cron(tab). Can someone
>> help me pls:
>>
>> I want to run flexbackup with the following backup plan:
>>   * monthly full
>>   * weekly diff
>>   * daily incr
>>
>> So I have installed sys-process/vixie-cron-4.1-r12 (and virtual/cron-0
>> and sys-process/cronbase-0.3.3).
>>
>> My crontab (created with "crontab -e") contains:
>>
>> 00 03 2-31 * 1-6     /usr/bin/flexbackup -set root -level incremental
>> 00 03 2-31 * 0       /usr/bin/flexbackup -set root -level differential
>> 00 03 1    * *       /usr/bin/flexbackup -set root -level full
>>
>> The problem I'm facing is, that incr and diff are executed each day
>> _both_ at the same time (which flexbackup luckily handles well).
>>
>> From my understanding the 2nd line (diff) should only be run on
>> sundays, and the 1st line (inc) should not run sundays.
>>
>>
>> Can someone please explain me what I'm doing wrong?
> 
> You are combining fields 3 and 5, those two work funny.
> 
> Unlike the other datetime specs, they are not ANDed, they are ORed.
> 
> Taking the first one, you obviously want the cron to run at 3 am
> between the 2nd and 31st of the month AND if the day is Mon-Sat.
> 
> What it is doing is running at 3am every day between the 2nd and 31st
> and also every day Mon-Sat (even if that is the 1st of the month).
> 
> Vixie cron does not directly allow you to do what you want. It's
> designed to run things periodically on a set schedule and doesn't do
> "except" very well.
> 
> A better approach would be to fire off a wrapper script every day at
> 3am. This script will then check for date, time and day of week and
> launch the app with the appropriate options. 
Thank you for the explanation!
Unfortunately that it's ORd :( ....

So I wrote this:

### /etc/cron.daily/run_flexbackup ###

#!/bin/bash

DOM=$(date +%d)
DOW=$(date +%w)

function run_backup() {
        # do some stuff
        /usr/bin/flexbackup -set root -level $1
        # do more stuff
}

if [ $DOM = 1 ]; then
        run_backup full
else
        if [ $DOW = 0 ]; then
                run_backup differential
        else
                run_backup incremental
        fi
fi


Bye,
Daniel

-- 
PGP key @ http://pgpkeys.pca.dfn.de/pks/lookup?search=0xBB9D4887&op=get
# gpg --recv-keys --keyserver hkp://subkeys.pgp.net 0xBB9D4887

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to