Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

archdelux

macrumors 6502
Original poster
Oct 12, 2008
332
2
Hello,

I've searched online but have been unable to find an adequate solution and was hoping someone could help me.

I want to plug in my computer into my USB dock, automatically mount my external HD, have TimeMachine do its thing automatically (so far, so good), but then immediately after the backup finishes, I want the computer to automatically unmount the HD. This will allow me to close the laptop and go somewhere without having to constantly eject the HD everytime I unplug the computer.

So - what I need is a program / script / etc that will tell the computer to eject the drive as soon as TimeMachine is done backing up.

Any ideas?

Thanks!!
 

haushinka

macrumors newbie
Aug 10, 2009
22
0
i've got the same problem. i tried looking online but found little help. the easiest solution i've seen is to hook up the external drive to a network via your router or desktop and then share the drive to your laptop. somehow, time machine is able to auto-mount/umount when it is backing up to a shared drive but unable to do the same when the drive is connected directly.

if someone else has an elegant solution please post. thanks.
 

0hy3ah

macrumors newbie
Mar 16, 2011
13
0
No, from what I've read and know Timemachine is a set it and forget it. It's not very customizable-except to choose what files you DON'T want backed up. Maybe some day someone will develop an app or program for that!
 

whiteatom

macrumors newbie
Jul 20, 2011
16
0
I have written a script that just mounts runs and unmounts 15 mins later.. it's the best I can do. It's only been a problem today after the lion upgrade.. more then 15 mins of crap to back up. I'd love to know if there is a way to tell when TimeMachine is done.. I had hoped the terminal would lockup until it was complete.. but the backed-helper exists as soon as Time Machine starts copying files.

Anyway.. here's my Applescript for anyone who wants it (adapted from somewhere on the internet...):
Code:
set myVolumeLabel to "Backup"

tell application "GrowlHelperApp"
	set the allNotificationsList to {"Disk Mounted", "Disk Unmounted", "Disk already mounted"}
	set the enabledNotificationsList to {"Disk Mounted", "Disk Unmounted"}
	register as application "Backup Script" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "Time Machine"
end tell

tell application "Finder"
	set diskDev to do shell script "diskutil list | grep \"" & myVolumeLabel & "\" | grep -o 'disk[1-9]*' "
	if not (disk myVolumeLabel exists) then
		do shell script "diskutil mountDisk " & diskDev
		tell application "GrowlHelperApp" to notify with name "Disk Mounted" title "Backup Drive Mounted" description "The Backup drive has been successfully mounted." application name "Backup Script" icon of application "Time Machine"
	end if
	do shell script "/System/Library/CoreServices/backupd.bundle/Contents/Resources/backupd-helper"
	delay 300
	do shell script "diskutil unmountDisk " & diskDev
	tell application "GrowlHelperApp" to notify with name "Disk Unmounted" title "Disk Unmounted" description "The Backup drive has been successfully unmounted." application name "Backup Script" icon of application "Time Machine"
end tell
 

brennj4

macrumors newbie
Mar 15, 2009
10
0
2 years later and I am still looking for a solution to this problem. I am constantly forgetting to unmount before I move the computer around. There is no need for it to be mounted all the time. A once a day backup and unmount would be sufficient for me.

Anyone found a solution to this??
 
Last edited by a moderator:

Alrescha

macrumors 68020
Jan 1, 2008
2,156
317
Anyone found a solution to this??

Here's a script I use on a Snow Leopard system. I have not tested it on newer versions of OS X. It's called by launchctl:

Code:
#!/bin/sh
# Check for a backup today, if none then mount the Time Machine volume
# and wait for Time Machine to run.  When the backup is over, unmount
# the Time Machine volume and exit.

# Set these variables or else
TMVOLUME="/Volumes/yourbackupvolume"
TMUUID="yourbackupvolumeuuid"
grep -q "Backup completed successfully." /var/log/system.log
if [ $? = 0 ]
	then
		 exit 0
fi

# No backup yet today.  See if the Time Machine volume is mounted
# and if it isn't, mount it.
test -d "$TMVOLUME"
if [ $? = 1 ]
	then
		/usr/sbin/diskutil mount "$TMUUID"
fi

# Wait a while for Time Machine to wake up and do a backup
sleep 300
grep -q "Backup completed successfully." /var/log/system.log
while [ $? = 1 ]
	do
		sleep 300
		grep -q "Backup completed successfully." /var/log/system.log
done

# Backup completed, unmount the Time Machine volume and exit
/usr/sbin/diskutil unmount "$TMUUID"

# Make really sure it unmounted?
sleep 300
test -d "$TMVOLUME"
while [ $? = 0 ]
	do
		sleep 300
		/usr/sbin/diskutil unmount "$TMUUID"
		test -d "$TMVOLUME"
done
	
exit

A.
 

DiegogDiegog

macrumors newbie
May 24, 2017
8
2
Miami Beach
Here's a script I use on a Snow Leopard system. I have not tested it on newer versions of OS X. It's called by launchctl:

Code:
#!/bin/sh
# Check for a backup today, if none then mount the Time Machine volume
# and wait for Time Machine to run.  When the backup is over, unmount
# the Time Machine volume and exit.

# Set these variables or else
TMVOLUME="/Volumes/yourbackupvolume"
TMUUID="yourbackupvolumeuuid"
grep -q "Backup completed successfully." /var/log/system.log
if [ $? = 0 ]
    then
         exit 0
fi

# No backup yet today.  See if the Time Machine volume is mounted
# and if it isn't, mount it.
test -d "$TMVOLUME"
if [ $? = 1 ]
    then
        /usr/sbin/diskutil mount "$TMUUID"
fi

# Wait a while for Time Machine to wake up and do a backup
sleep 300
grep -q "Backup completed successfully." /var/log/system.log
while [ $? = 1 ]
    do
        sleep 300
        grep -q "Backup completed successfully." /var/log/system.log
done

# Backup completed, unmount the Time Machine volume and exit
/usr/sbin/diskutil unmount "$TMUUID"

# Make really sure it unmounted?
sleep 300
test -d "$TMVOLUME"
while [ $? = 0 ]
    do
        sleep 300
        /usr/sbin/diskutil unmount "$TMUUID"
        test -d "$TMVOLUME"
done
   
exit

A.

Hi, would this work on High Sierra?
Also in case, things break, is there a way to revert it?
 

bunjamins

macrumors newbie
Jun 26, 2018
2
0
Hi, would this work on High Sierra?
Also in case, things break, is there a way to revert it?


It will not work, the log no longer exists now that sierra has moved to mostly binary logging with the "log" utility

instead of the grep -q line, you'd need to do something like the following:

log show --style syslog --predicate 'senderImagePath contains[cd] "TimeMachine" AND eventMessage contains[cd] "Backup completed successfully"' --info --last 12h| grep -v 'Filtering\|Timestamp'

there might be a cleaner way to get a return code, but that would show the log lines for timemachine that show a backup completed. I'll test it soon and let you know what i work out.
[doublepost=1530033898][/doublepost]UPDATED, working great for me on High Sierra 10.13.5
I added a part to get the uuid from the diskutil, all you have to change is the TMVOLUME to match your disk name
I also updated the log grep to use the binary utility, it prints the lines it finds, if you cron it you might want to write it to dev null.

Code:
#!/bin/sh
# Check for a backup today, if none then mount the Time Machine volume
# and wait for Time Machine to run.  When the backup is over, unmount
# the Time Machine volume and exit.

# Set these variables or else
# for TMVOLUME ls -l /Volumes/ and paste the entire path including spaces in the quotes replace 'backup drive' below, TMFREQ is how recently you care to look
for a backup

TMVOLUME="backup drive"
TMFREQ="12h"

TMUUID=$(diskutil info "$TMVOLUME" | grep 'Volume UUID' | cut -f 2 -d ':'| awk '{$1=$1};1')

log show --style syslog  --predicate 'senderImagePath contains[cd] "TimeMachine" AND eventMessage contains[cd] "Backup completed successfully"' --info --last $TMFREQ| grep -v 'Filtering\|Timestamp'
if [ $? = 0 ]
        then
                sleep 300
                /usr/sbin/diskutil unmount "$TMUUID"
                test -d /Volumes/"$TMVOLUME"
                 exit 0
fi

# No backup yet today.  See if the Time Machine volume is mounted
# and if it isn't, mount it.
test -d /Volumes/"$TMVOLUME"
if [ $? = 1 ]
        then
                /usr/sbin/diskutil mount "$TMUUID"
fi

# Wait a while for Time Machine to wake up and do a backup
sleep 300
log show --style syslog  --predicate 'senderImagePath contains[cd] "TimeMachine" AND eventMessage contains[cd] "Backup completed successfully"' --info --last $TMFREQ| grep -v 'Filtering\|Timestamp'
while [ $? = 1 ]
        do
                sleep 300
        log show --style syslog  --predicate 'senderImagePath contains[cd] "TimeMachine" AND eventMessage contains[cd] "Backup completed successfully"' --info --last $TMFREQ| grep -v 'Filtering\|Timestamp'
done

# Backup completed, unmount the Time Machine volume and exit
/usr/sbin/diskutil unmount "$TMUUID"

# Make really sure it unmounted?
sleep 300
test -d /Volumes/"$TMVOLUME"
while [ $? = 0 ]
        do
                sleep 300
                /usr/sbin/diskutil unmount "$TMUUID"
                test -d /Volumes/"$TMVOLUME"
done

exit
 

bunjamins

macrumors newbie
Jun 26, 2018
2
0
Running great through launchd with a plist like this:

Code:
<?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>ben.backupumounter</string>
        <key>ProgramArguments</key>
        <array>
          <string>/usr/bin/nohup /tmp/backupumounter.sh &</string>
        </array>
        <key>StartInterval</key>
        <integer>1800</integer>
    </dict>
</plist>


This way i just run through the unmount every 30 minutes, this, with the sleeps in the script with account for 99% of times where i disconnect from my dock at my desk, hopefully minimizing the times where my drive gets corrupted due to a unclean disconnect. I've had to reformat my timemachine drive twice in hte last year due to corruption from un-ejected disconnect.
 

diegog

macrumors member
Nov 25, 2018
30
3
Miami, FL
Hello,

I've searched online but have been unable to find an adequate solution and was hoping someone could help me.

I want to plug in my computer into my USB dock, automatically mount my external HD, have TimeMachine do its thing automatically (so far, so good), but then immediately after the backup finishes, I want the computer to automatically unmount the HD. This will allow me to close the laptop and go somewhere without having to constantly eject the HD everytime I unplug the computer.

So - what I need is a program / script / etc that will tell the computer to eject the drive as soon as TimeMachine is done backing up.

Any ideas?

Thanks!!


Hello, I forgot to get back here and post the solution.
Is called TimeMachineScheduler.app
It mounts and unmounts the time machine drive as an option, in the advanced tab!

It worked for me and still working for me.
 

James_C

macrumors 68030
Sep 13, 2002
2,847
1,897
Bristol, UK
Another option if your WiFi router has a USB port and supports Time Machine, you could attach an external hard disk to your router. Works in the same way as Apple’s old Airport Time Capsules. Your laptop will only Backup to time machine when you are connected to your home WiFi network. The other advantage is you can backup multiple laptops if you have more than one in your household to the same device, without having to connect and disconnect to different machines.
 

martindinicolino

macrumors newbie
Apr 20, 2021
11
1
Is there any other solution for this? I tried multiple times contacting TimeMachineScheduller support department without any luck.
I happened to speak to the Apple support team yesterday, so whilst I was at it I just outright asked if it would be possible to automatically unmount a TM drive upon completion of a backup. According to them the reason they do not have this feature built in, is that there is a chance of damaging the backups (would anyone be able to help and explain how? asking for a friend). So I guess that's why TimeMachineScheduler isn't doing it anymore either.

That being said, here is the SOLUTION: using LaunchControl and the developer‘s help we were able to get my to drives to automatically backup with TimeMachine and unmount upon completion. He was extremely nice and patient and even a newbie like myself was able to get it to work with his help. So I can definitely recommend this method.

My next goal would be to have a HomeKit-enabled smart plug power on the drives at a specific time of the day, then let LaunchControl do it‘s thing and power off the smart plug as soon as it's done. Not sure how to make the Mac speak to to the smart plug yet, but I'll keep looking and would be open to suggestions. Any help would be highly appreciated. https://forums.macrumors.com/thread...f-upon-timemachine-backup-completion.2297742/
 
Last edited:

diegog

macrumors member
Nov 25, 2018
30
3
Miami, FL
Hello,

I've searched online but have been unable to find an adequate solution and was hoping someone could help me.

I want to plug in my computer into my USB dock, automatically mount my external HD, have TimeMachine do its thing automatically (so far, so good), but then immediately after the backup finishes, I want the computer to automatically unmount the HD. This will allow me to close the laptop and go somewhere without having to constantly eject the HD everytime I unplug the computer.

So - what I need is a program / script / etc that will tell the computer to eject the drive as soon as TimeMachine is done backing up.

Any ideas?

Thanks!!
I believe there would be a way through Carbon Copy Cloner because they have snapshots compatible with Time Machine Snapshots.
 

martindinicolino

macrumors newbie
Apr 20, 2021
11
1
I posted the solution in my last comment, which is still awaiting approval.

If you can‘t wait until the aproval: search the web for an application called LaunchControl, it‘s developer was able to help me to get it working through his app.
 
Last edited:

martindinicolino

macrumors newbie
Apr 20, 2021
11
1
SOLUTION: using LaunchControl and the developer‘s help we were able to get my to drives to automatically backup with TimeMachine and unmount upon completion. He was extremely nice and patient and even a newbie like myself was able to get it to work with his help. So I can definitely recommend this method.
 

diegog

macrumors member
Nov 25, 2018
30
3
Miami, FL
I happened to speak to the Apple support team yesterday, so whilst I was at it I just outright asked if it would be possible to automatically unmount a TM drive upon completion of a backup. According to them the reason they do not have this feature built in, is that there is a chance of damaging the backups (would anyone be able to help and explain how? asking for a friend). So I guess that's why TimeMachineScheduler isn't doing it anymore either.

That being said, here is the SOLUTION: using LaunchControl and the developer‘s help we were able to get my to drives to automatically backup with TimeMachine and unmount upon completion. He was extremely nice and patient and even a newbie like myself was able to get it to work with his help. So I can definitely recommend this method.

My next goal would be to have a HomeKit-enabled smart plug power on the drives at a specific time of the day, then let LaunchControl do it‘s thing and power off the smart plug as soon as it's done. Not sure how to make the Mac speak to to the smart plug yet, but I'll keep looking and would be open to suggestions.
Thanks, but LaunchControl seems a bit cumbersome for me, too many options :p. I'm almost sure there's a simpler way with Carbon Copy Cloner. I've been using it for years but never thought of using it in that way.
My real need for Time Machine is only in the case I need to restore my mac from a backup through a macOS recovery mode using the migration assistant feature.
 
  • Like
Reactions: jagooch

diegog

macrumors member
Nov 25, 2018
30
3
Miami, FL
Thanks, but LaunchControl seems a bit cumbersome for me, too many options :p. I'm almost sure there's a simpler way with Carbon Copy Cloner. I've been using it for years but never thought of using it in that way.
My real need for Time Machine is only in the case I need to restore my mac from a backup through a macOS recovery mode using the migration assistant feature.
I happened to speak to the Apple support team yesterday, so whilst I was at it I just outright asked if it would be possible to automatically unmount a TM drive upon completion of a backup. According to them the reason they do not have this feature built in, is that there is a chance of damaging the backups (would anyone be able to help and explain how? asking for a friend). So I guess that's why TimeMachineScheduler isn't doing it anymore either.

That being said, here is the SOLUTION: using LaunchControl and the developer‘s help we were able to get my to drives to automatically backup with TimeMachine and unmount upon completion. He was extremely nice and patient and even a newbie like myself was able to get it to work with his help. So I can definitely recommend this method.

My next goal would be to have a HomeKit-enabled smart plug power on the drives at a specific time of the day, then let LaunchControl do it‘s thing and power off the smart plug as soon as it's done. Not sure how to make the Mac speak to to the smart plug yet, but I'll keep looking and would be open to suggestions.
So if I take the LaunchControl route, would you share the Job with me so I can customize it with my drive information?
Thanks
 

jagooch

macrumors 6502a
Jul 17, 2009
807
249
Denver, co
I just purchased an app called "Jettison" that claims to eject drives when the system sleeps. I just installed it but I'll report back how well it works after I have some time to test it.

I undock my macbook on short notice, so it will be nice if this works. So many times I'm late for work or another event where I need my macbook, so I will just grab it from the dock and run. Then I scolded by my Macbook that I didn't eject the disk. Tsk tsk!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.