ramblings

Using anacrontab in ubuntu (backintime as example)

Anacron is similar to cron, a tool to schelude programs on linux systems. The only difference is that anacron does not assume that computer is online all the time. Anacron executes missed commands on boot. Anacron requires root access, unlike cron which can schelude tasks for non root users too. Anacron cannot schelude recurring tasks with a period less than a day. For example, anacron cannot be used to schelude a recurring task with a period of an hour (hourly task).

Anacrontab has anacrontab, similar to crontab, located in /etc/anacrontab. My ubuntu installation has the following contents as default

First column means period, 1 equals daily, 7 equals weekly and @monthly equals monthly. Second column means delay which is the delay (in minutes) the commands will be executed after system start. For example daily commands will be executed 5 minutes after start each day.

We can see that anacron is configured to launch scripts in /etc/cron.daily, /etc/cron.weekly and /etc/cron.monthly folders. Simple enough.

If we want to add a daily script, we just make a new script in /etc/cron.weekly folder (you can use other scripts as examples) and give it execution permissions by

One important thing to remember is that script name cannot contain periods! This is a known anacron bug.

For excellent backup program, Back In Time, following script (/etc/cron.daily/back-in-time) will schelude the daily back up daily:

#!/bin/sh
nice -n 19 /usr/bin/backintime --backup-job >/dev/null 2>&1

Anacron is a perfect scheluding tool for desktop ubuntu systems.

EDIT:

I was wondering one day why anacrob ’replaces’ crontab when it comes to daily, weekly or monthly jobs. Ubuntu default system-wide crontab looks something like this:

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don’t have to run the `crontab’
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

Crontab cleverly uses test -x to find if /usr/sbin/anacron exists and has executable bit set. If true, nothing is done. If anacron is not installed, all scripts in /etc/cron.xxxx are executed. This is why (system-wide) crontab does not nothing when anacrontab is installed.