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
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"
-
Any idea how to create a hook so that this is displayed when a backup finishes?– slhckNov 13, 2011 at 11:15
-
@slhck Sure, use
launchd
and theWatchPaths
directive to start a small shell script that compares the current with the previous (stored somewhere) output ofdefaults
, and only callsgrowlnotify
if it changed. Due to OS X's atomic saves, the file is recreated each time it's written: Verify usingstat /private/var/db/.TimeMachine.Results.plist
, all ofctime
,atime
mtime
andbtime
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
Another option (requires the backup volume to be mounted): date -jf "%Y-%m-%d-%H%M%S" "$(tmutil latestbackup | sed 's|.*/||')" +"%F %T"
-
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