I use Time Machine to back up my home iMac to a USB external hard drive. But I don’t want the Time Machine volume mounted all of the time. It adds clutter and slows down Finder.
I’ve been using a shell script and a Launch Agent to automatically mount my Time Machine volume, back it up, and unmount it again.
Since this takes care of running Time Machine, I have Time Machine turned off in System Preferences.
The shell script used to be more complicated, but Apple has been been improving their tools. You could actually do this in three commands:
--block
flag prevents the command from
exiting before the backup is complete.Everything else is either logging or to make sure that I only eject the volume if it wasn’t mounted to begin with. In particular, line 4 checks if the Time Machine volume is mounted at the beginning.
|
|
Nothing complicated here. This uses launchd to run the shell script every two hours and capture the output to a log file.
I save this as “net.nathangrigg.time-machine.plist” in “/Library/LaunchDaemons”, so that it is run no matter who is logged in. If you do this, you need to use chown to set the owner to root, or it will not be run.
If you are the only one that uses your computer, you can just save it in “~/Library/LaunchAgents”, and you don’t have to worry about changing the owner.
Either way, run launchctl load /path/to/plist
to load your agent for the first time.
(Otherwise, it will load next time you log in to your computer.)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>net.nathangrigg.time-machine</string>
<key>Program</key>
<string>/Users/grigg/bin/time-machine.sh</string>
<key>StandardErrorPath</key>
<string>/Users/grigg/Library/Logs/LaunchAgents/time-machine.log</string>
<key>StandardOutPath</key>
<string>/Users/grigg/Library/Logs/LaunchAgents/time-machine.log</string>
<key>StartInterval</key>
<integer>7200</integer>
</dict>
</plist>
OS X will still mount your Time Machine volume every time you log in. You can fix this by adding one line to “/etc/fstab” (which you may need to create).
UUID=79CA38B7-BA13-4A15-A080-D3A8B568D860 none hfs rw,noauto
Replace the UUID with your drive’s UUID, which you can find using
diskutil info "/Volumes/Time Machine Backups"
. For more detailed instructions,
see this article by Topher Kessler.