3

How can I determine the date and time of the latest Time Machine backup from the command line, so I can e.g. display it in an AppleScript dialog or via Growl's growlnotify?

2 Answers 2

3

Time Machine state information is stored in /private/var/db/.TimeMachine.Results.plist. Use defaults to read the BACKUP_COMPLETED_DATE value:

$ defaults read /private/var/db/.TimeMachine.Results BACKUP_COMPLETED_DATE
2011-11-13 08:28:07 +0000

It's in UTC, but you can easily convert it to your local time zone.


To display it using growlnotify, run something like the following:

/usr/local/bin/growlnotify -m "$( date -jf "%F %T %z" "$( defaults read /private/var/db/.TimeMachine.Results BACKUP_COMPLETED_DATE )" +"%d.%m.%Y %H:%M" )" "Latest Time Machine Backup"

enter image description here

3
  • Any idea how to create a hook so that this is displayed when a backup finishes?
    – slhck
    Nov 13, 2011 at 11:15
  • @slhck Sure, use launchd and the WatchPaths directive to start a small shell script that compares the current with the previous (stored somewhere) output of defaults, and only calls growlnotify if it changed. Due to OS X's atomic saves, the file is recreated each time it's written: Verify using stat /private/var/db/.TimeMachine.Results.plist, all of ctime, atime mtime and btime are the same.
    – Daniel Beck
    Nov 13, 2011 at 11:39
  • I tested this: It works when watching /private/var/db/ (the directory).
    – Daniel Beck
    Nov 13, 2011 at 18:17
2

Another option (requires the backup volume to be mounted): date -jf "%Y-%m-%d-%H%M%S" "$(tmutil latestbackup | sed 's|.*/||')" +"%F %T"

1
  • Didn't know about tmutil -- and using that I can start the backup any time. Thanks for the answer! The connection requirement is pretty inconvenient unfortunately for the purpose of this question.
    – Daniel Beck
    Nov 14, 2011 at 4:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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