This is the follow-up to the previous article on backing up a Mac to a Windows Home Server machine.
So now what’s the next step? Obviously, we need to schedule our Automator jobs to run, unattended, so that we can stop thinking about backups and start thinking about what to do with all of our newfound free time.
Launchd is what we’re supposed to use for scheduling on a Mac these days, but it just seems far too complicated to get into easily and quickly. The Mac’s BSD underpinnings still allow cron jobs to run, though, and there’s a plethora of information out there on cron. So, let’s use that.
I won’t go into too much detail on cron itself since, as I stated, there’s plenty out there on it. But the basics are that cron allows the user to schedule things to happen at specific times of day, on specific days. It’s not as full-featured or wizard-driven as Windows’ Task Scheduler (which likewise got far more complex with the release of Vista), but it does the trick nicely for our backup purposes.
First, we need to get a little comfortable with the terminal app. It’s text-based entry and response, but don’t be too afraid of that; it’s actually pretty simple what we’re about to do.
Start the Terminal app on OSX and type pwd and press enter. This tells you where you are in the folder hierarchy. You’re probably in /Users/<your user name>/. Go ahead and type ‘cd ~/Documents’ and press enter. This places you in your Documents folder. Type ‘ls’ and press enter and you’ll see a list of files which are probably familiar.
Next we want to check our cron table. Type ‘crontab –l’ (the letter el, not the number one) and press enter. This should list your cron table, which is probably empty if you haven’t set anything up. Now let’s extract the cron table to a file that we can edit. Type the command ‘crontab –l >crontab.txt’ and press enter. This creates a file crontab.txt in your Documents folder (since that’s where we are, remember?) that can be edited.
Again, it’s probably empty, but go ahead and edit it anyway. Here’s what mines looks like.
Let’s go over this line by line. The first line is a comment, to help us remember what’s in each record. The pound character causes the entire line to be ignored. Next there is a series of records, each of which defines a scheduled job. The first of these is:
0 8 * * 1-5 automator /Users/…/Documents/BackupMusicToAcerHome.workflow
This tells cron that at 8:00 (0th minute of the 8th hour) on any (*) day of the month, in any (*) month of the year, on Monday through Friday (weekdays 1-5… 0 is Sunday), run the command that’s the rest of the line.
“.workflow” is the default extension for Automator actions, and the automator program executes the Automator script named. So, in essence, every Monday through Friday at 8am, I run my music backup script.
Note the other lines, which are similar in structure, just changing the time of day and the Automator script being executed.
Once you’ve edited your crontab.txt file and saved it, exit out of your editor and go back to the Terminal app. Type in the following command:
crontab crontab.txt
This loads your schedule into cron for execution on the schedule you defined.
Pretty easy, huh? Now I have a fully-scheduled backup of all my iTunes files to my Windows Home Server. The backups run every weekday throughout the morning, which is fine, since I’m at work anyway.
Oh, one thing to note. The first time you execute these backups, they will take a long time to run, depending on how much music and such you have. After that, though, only the changed files will get copied by rsync. My backup scripts run for a few seconds up to a few minutes (if I’ve ripped new movies that need backing up).
Let me know how you back up your data. Is there a better solution? Is it just as cheap (free) as this one? Tell me in the comments below.

One Comment on Scheduling Your Backup in Cron