How do I set Time Machine to eject my external Time Machine backup drive automatically after each backup?
-
4An interesting observation: when doing a TimeMachine backup to a network drive TimeMachine will automatically mount, backup and then unmount the remote TimeMachine share on the network drive. I wonder if you could exploit that to achieve what you want?– Ian C.May 25, 2011 at 14:39
4 Answers
~/bin/timemachine:
#!/bin/bash
d="Time Machine" # (change this to match the name of your backup drive)
diskutil mount "$d" && tmutil startbackup -b && diskutil eject "$d"
~/Library/LaunchAgents/timemachine_eject.plist:
<?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>timemachine_eject</string>
<key>Program</key>
<string>/Users/username/bin/timemachine</string> <!-- Replace "username" with your username. "~/bin/timemachine" doesn't work -->
<key>StartInterval</key>
<integer>120</integer> <!-- run every two minutes for testing. -->
<!-- Change this to a higher number like 43200 (run every 12 hours) once you've confirmed it works. -->
</dict>
</plist>
Make the script executable, unload the default plist, and load the new one:
chmod +x ~/bin/timemachine
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.backupd-auto.plist
launchctl load ~/Library/LaunchAgents/timemachine_eject.plist
Any time you want to make changes to the plist file, you have to unload and load it:
launchctl unload ~/Library/LaunchAgents/timemachine_eject.plist
launchctl load ~/Library/LaunchAgents/timemachine_eject.plist
-
1I love this solution, I further automated this process to mount and unmount work when I plug my drive and on a schedule. Visit my post here: somethinginteractive.com/blog/2013/07/24/… Jul 31, 2013 at 6:07
-
On Maveriks this did not work for me, strangely the script looped and the backup was done continuously. The following change works though: <key>ProgramArguments</key> <array> <string>/Users/martin/bin/timemachine</string> </array>– MartinJan 5, 2015 at 14:21
-
somethinginteractive.com is down, archived version: web.archive.org/web/20160409130936/http://… Nov 27, 2017 at 18:03
-
-
com.apple.backupd-auto.plist
doesn't seem to exist anymore on OS Ventura, and I ideally don't want to deactivate the default plist. I've made another version which might be helpful to others here: github.com/micahcarroll/auto-eject-time-machine– mdcAug 27 at 21:38
There might be a better way, but one solution might be to Applescript it. I haven't yet found any way to run an applescript after a backup, but you could:
- Turn off automatic TM backup
- Set up an applescript to run TM
- Some googling turned up this line to force an immediate TM build:
do shell script "/System/Library/CoreServices/backupd.bundle/Contents/Resources/backupd-helper >/dev/null 2>&1 &"
- Some googling turned up this line to force an immediate TM build:
- Add a line to eject the disk afterwards.
eject disk somedrivename
If you want this to happen on a regular basis, you could attach it to a cron job.
-
1Looks promising, but there needs to be some way to start #3 only after #2 ends.– Adam AAug 30, 2010 at 14:27
-
If I remember, I'll try to rig this up and test it when I get home tonight (and try to enforce waiting for the backup to finish before ejecting). Aug 30, 2010 at 14:49
-
Haven't tried this, but it looks like it might work:
Ejects external drives when going to sleep and remounts them waking from sleep.
No longer available on app store, available here instad: https://www.stclairsoft.com/Jettison/ or via brew cask install jettison
. Well worth the $5 after the trial expires.
-
What is this? Could you give more content? How does it answer the question?– ThinkrJun 12 at 14:24