On Mon, 09 Jan 2012 14:02:23 +0100
Daniel Troeder <dan...@admin-box.com> wrote:

> 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 :( ....

It does make sense in a way :-)  The man page says:

"Commands are executed by cron(8) when the minute, hour, and month of year 
fields
match the  current time,  and  when  at least one of the two day fields
(day of month, or day of week) match the current time."

If it didn't work as it does, a cron that specified both day fields
would equate to something like "on the 1st of a month, but only if it's
a Sunday" which is rare. The intention is that you use either the date
field or the day of week, but not both

> 
> 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

Yup, that's the better way. And it comes with the benefit that the cron
is now simple and the wrapper script documents how and what it runs.
Overall, a better solution i think.


-- 
Alan McKinnnon
alan.mckin...@gmail.com


Reply via email to