Now we’ve worked out what files you want backed up, and we’ve sorted automatic authentication, the only thing left to do is schedule our backups. Unfortunately we can’t make use of the very handy iSync or Backup tools to do this (Apple don’t seem keen on opening up these tools up, as they no-doubt help sell expensive .Mac accounts).
cron is available on all *NIX systems, and is a well established solution to running all kinds of house keeping tasks. On OSX 10.4 however
cron is being phased out in favour of
launchd which we’ll look at next.
As of OSX 10.4 a new daemon called launchd has been added. Eventually this will replace tools such as
xinetd – however it’s low on the userfriendly scale right now. Unlike
launchd requires XML files which can be a pain to edit without something like the shareware program launchd editor. Hopefully later OSX releases might bundle a decent UI for managing it.
Anacron + launchd – for those who like to switch their computers off
cron and the newer
launchd suffer from the same problem when it comes to running routine housekeeping tasks – if the computer isn’t on when a task is scheduled, the task won’t get run, and even when you switch the computer on again, neither tool can work out that it should try and catch up by running the task on startup.
So using either
launchd means that if we use either task to manage our backups, the computer has to be on when the backup is scheduled to run.
Anacron attempts to solve these deficiencies. It stores a record of when each job was last run, so on startup it can work out if it needs to catch up. This is especially handy for laptops which are probably only on for a few hours a day.
Depending on your operating system, you can either get
anacron setup to work with
launchd. Assuming you take the
launcd approach, grab Ronald Florence’s highly useful Anacron for OSX 10.4 installer. Once installed, you should have a file
/etc/anacrontab which will look like this:
#period delay job-identifier command 1 5 cron.daily periodic daily 7 10 cron.weekly periodic weekly 30 15 cron.monthly periodic monthly
The first field is the frequency of the job –
1 means daily,
7 means weekly and
30 means monthly. The second value is the delay in minutes between
anacron realising a job needs to be run, and it actually getting scheduled. The third field is a unique identifier for the job, and finally the command itself.
To simplify things we should create a simple script which contains our
rsync command(s) – for now you can place it into your
bin directory, and call it something sensible like
backup. Next, assuming you want to run the backup job daily, add the following line to
1 10 backup.user /Users/johnsmith/bin/backup
To make sure
anacron is working (and is picking up your job) simply start
Console.app, and select
Open System Log from the
File menu – you should see its output. If you need to tweak your backup job, you can remove the record of the previous run
/var/spool/anacron/ – it should contain one file per record in
anacrontab. Then, you can force
anacron to rerun the job by executing
And there you have it! Trouble free, secure backups that will get run even if you switch your computer on for only a few hours each day.