Last active
August 29, 2015 14:18
-
-
Save dmann/cde3662a604bd7057ac2 to your computer and use it in GitHub Desktop.
Overriding Time Machine's default behavior to do a single backup when a backup drive is connected and eject the drive when the backup is complete.
This file contains 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
<!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>com.apple.TimeMachine_OnMount</string> | |
<key>StartOnMount</key> | |
<true/> | |
<key>Program</key> | |
<string>/usr/local/bin/timemachine_backup.sh</string> | |
</dict> | |
</plist> |
This file contains 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 | |
#------------------------------------------------------------------------------------------ | |
# Launch control commands run to override Apple defaults | |
# sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.backupd-auto.plist | |
# launchctl load ~/Library/LaunchAgents/com.apple.TimeMachine_OnMount.plist | |
#------------------------------------------------------------------------------------------ | |
# Set the drive name that we mount for our backups | |
# Conditional argument: if mounted entry has the volume name in the variable string | |
backup_mount_point=`/usr/bin/tmutil destinationinfo | grep 'Mount Point' | head -1 | cut -d : -f 2 | sed 's/^ *//'` | |
if [ "$backup_mount_point" != '' ]; then | |
echo Drive is mounted, so: backup and then eject | |
/usr/bin/tmutil startbackup -b -r && | |
/usr/sbin/diskutil eject "$backup_mount_point" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment