Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
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

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/ AutoBackup | sed -e 's/0/false/' | sed -e 's/1/true/'`

This is a fix for the fact that defaults read gives 0 and 1 for bools but defaults write only accepts true and false

echo "Saved Time Machine state: AutoBackup = $save"

trap "echo 'Restoring Time Machine state'; defaults write /Library/Preferences/ 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/ 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
share|improve this question

marked as duplicate by bmike Nov 28 '12 at 16:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 1 down vote accepted

There is a duplicate question covering this, but the answer is tmutil status will tell you any time a backup is in progress as well as details about the backup.

You can use tmutil then to turn off backups if desired or even read the list of backups so you can predict how many minutes to the next scheduled backup. We had something similar and then just decided to kick off a backup when the copy finishes so that whether or not a backup was in progress - we get a strong chance of a consistent backup at the end of the copy operation.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.