Scheduling backups on macOS Sierra and High Sierra


MacOS Sierra (OS X 10.12) modified the behavior of Time Machine from doing hourly backups to using a heuristic that decides whether to do a backup based on recent activity. For most users that’s a better approach since it makes it less likely the user will notice the performance impact of backups and will increase how far back in time backups are available. However, if you’re a software developer the new behavior is problematic. That’s because when I’m writing code, do something stupid, and need to revert the project workspace to an earlier state I always want to be able to select a state in the near past. When backups occur at irregular intervals you might find that the most recent backup was made so long ago as to be borderline useless.

Configuring Time Machine to suit the needs of a software developer turns out to be surprisingly simple. Thanks to Apple providing not just simple to use GUIs but excellent CLI tools. In this case the command you need is tmutil. The first step is to disable automatic backups using the System Preferences GUI or by running sudo tmutil disable. The second step is to setup a cron job by running crontab -e and adding an entry like the following:

# Every hour during the times we're likely to be working do a Time Machine
# backup.
0 7-22 * * * tmutil startbackup

That initiates a backup at the top of every hour from 0700 to 2200 hours every day of the week. I skip the other eight hours of each day because I’m unlikely to be writing code at that time. Voila! Now I can be assured that if I need to recover from a stupid mistake that a simple git checkout can’t help with I won’t have to recover more than an hour’s worth of work.