Is there a bash command to check to see if Time Machine has finished backing up?
To run some syncs to remote servers to have their data included in TimeMachine backups I used to use a script like the following to avoid syncing while TimeMachine runs and not get half synced backups.
The detection part of the script that waits until TimeMachine stopped working on 10.8 so I'm looking for a working replacement for it.
#!/bin/sh -x while ps -e | grep backupd | grep -v grep; do echo "Time Machine is running, waiting ..." sleep 60 done
The above waits until a TimeMachine run thats already underway finishes.
This is the part that doesn't work on 10.8 anymore since backupd is shown allways in
ps -e output. So it will wait forever.
The rest of the script still works fine and is only put here for reference if anyone needs switching TimeMachine off during a script and then safely on again afterwards.
save=`defaults read /Library/Preferences/com.apple.TimeMachine AutoBackup | sed -e 's/0/false/' | sed -e 's/1/true/'`
This is a fix for the fact that defaults read gives
bools but defaults write only accepts
echo "Saved Time Machine state: AutoBackup = $save" trap "echo 'Restoring Time Machine state'; defaults write /Library/Preferences/com.apple.TimeMachine AutoBackup -bool $save" EXIT HUP INT QUIT ABRT TERM
Here we restore the former time machine state when the script stops for whatever reasons -- don't want to accidentally turn time machine off and nobody notices.
defaults write /Library/Preferences/com.apple.TimeMachine AutoBackup -int 0
Switch TimeMachine off, not sure why
-int 0 works here maybe the whole
sed business is not really necessary anymore? I think it changes the default to int which is ok for off (?)
# ... script that does some remote syncing with other machines while time machine is not running