Turn Time Machine off/on using cron


Issue: Let's say, just for fun, I wanted to be able to turn Time Machine off and on at specific times during the day (e.g., if I only want Time Machine to run at night). How can I do that?


Solution: It's cron to the rescue...

1) Create two bash scripts that will edit the Time Machine preferences file to turn Time Machine on or off. This is accomplished using the command

defaults write /Library/Preferences/com.apple.TimeMachine \
   AutoBackup -boolean YES

to turn Time Machine on or

defaults write /Library/Preferences/com.apple.TimeMachine \
   AutoBackup -boolean NO

to turn Time Machine off. You can also just download my scripts: TMon.sh and TMoff.sh.

2) Create a hidden directory in your home directory in which to store the scripts, using the following command in a Terminal or xterm window:

mkdir ~/.cron.daily

and move the scripts into it. For example, if the scripts are currently in your Downloads folder, then use the command:

mv ~/Downloads/TM*.sh ~/.cron.daily

3) Create a .crontab file in your home directory. See Use cron to schedule automatic tasks for more information about setting up and using cron. Basically you will want your .crontab file to look like this:

# minute hour mday month wday command
00 08 * * 1-5 /Users/yourname/.cron.daily/TMoff.sh
00 17 * * 1-5 /Users/yourname/.cron.daily/TMon.sh

Change yourname to your short user (login) name. This would turn Time Machine off at 8am, and then back on at 5pm, on Monday through Friday. Since Time Machine is turned on at 5pm on Friday, it will run through the weekend and then turn off again at 8am on Monday. If you want Time Machine to turn off/on on every day of the week, then replace 1-5 with *.

4) Don't forget to start cron after setting this up, using the command

crontab /Users/yourname/.crontab

5) A few caveats:

(a) If you are already using cron for other tasks, then the Time Machine control scripts can be added to your existing .crontab file. Don't forget to stop cron before editing the file, then restart it afterward – see Use cron to schedule automatic tasks.

(b) cron will not run if the computer is asleep, so keep that in mind if using this procedure on a laptop or other computer that is configured to sleep when not in use.

(c) Time Machine will not make backups while it is turned off. Are you certain that you want to do this?
OS X banner
Update Status: 28 Oct 2012 (updated); 29 Sep 2009 (added)