Created
October 8, 2013 16:42
-
-
Save pjv/6887598 to your computer and use it in GitHub Desktop.
Back up a mac to an external USB-connected hard disk using Time Machine but keep the hard disk unmounted in between backups.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>mac.backup</string> | |
<key>RunAtLoad</key> | |
<true/> | |
<key>StartInterval</key> | |
<integer>3600</integer> | |
<key>Program</key> | |
<string>/path/to/tm_backup.sh</string> | |
</dict> | |
</plist> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This is the name of your backup disk | |
BACKUP_DISK="Backup" | |
# Mount the disk if it is unmounted | |
if ! mount | grep "$BACKUP_DISK" ; then | |
diskutil mount "$BACKUP_DISK" | |
fi | |
# If the drive is successfully mounted, do the backup (nothing will happen if disk is not connected) | |
if mount | grep "$BACKUP_DISK" ; then | |
# do backup, then unmount backup volume | |
tmutil startbackup --auto --block && | |
diskutil eject "$BACKUP_DISK" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
These two files together let you back up to an external USB-connected hard disk using Time Machine on OS X but keep the hard disk unmounted in between backups.
You can put tm_backup.sh anywhere you want. You need to make it executable (
chmod 755
). I put mine inside the bin directory in my home directory.You need to put
mac.backup.plist
inside theLaunchAgents
folder insideLibrary
in your home directory.You need to configure two things inside the scripts:
tm_backup.sh: configure the name of your backup disk as the variable BACKUP_DISK
mac.backup.plist: configure the full path to where you put tm_backup.sh where it says
<string>/path/to/tm_backup.sh</string>
Finally, once everything is configured and where it needs to be, issue this command in the terminal:
launchctl load ~/Library/LaunchAgents/mac.backup.plist
It should immediately mount your backup disk (if unmounted) and start a Time Machine backup and then unmount your backup disk when the backup is completed. Then every hour it will do the same thing again. If you want backups more or less often than once an hour, change the 3600 number to the number of seconds you want in between backups.
I keep the switch for Time Machine in the system preferences pane set on OFF.