Mac – bash command to check to see if Time Machine has finished backing up

applescriptbackupbashtime-machine

I'm writing a script that will rsycnc my Time Machine directory to a remote server using ssh. I've switched from a shell script to an AppleScript and then back to an Apple script and I don't really care what kind of script the solution will require.

I've had success starting the backup process with this little snippet of code.

do shell script "/System/Library/CoreServices/backupd.bundle/Contents/Resources/backupd-helper >/dev/null 2>&1 &"

What I'm trying to do now is have an rsync command performed once that backup is completed. Is there any clean way in AppleScript to check to see if the backup process is completed? Or is there a good "hook" that you can use in bash to check to see if it's completed?

Best Answer

Here's one way - I know it's nowhere near a "proper" solution, but I imagine it would work.

ps ax | grep "/System/Library/CoreServices/backupd.bundle/Contents/Resources/backupd-helper" | grep -v 'grep'

What it does is search the process list for the backupd-helper process, then filters out the grep command itself from showing up. If the command returns > 0 results, the backupd-helper process is still active. If not, the process has ended, and so you might assume it's done.