Mac – Get latest Time Machine backup when backup disk is unplugged

automationbackupscripttime-machine

I know i can get the time stamp of the latest Time Machine backup with the command tmutil latestbackup | grep -E -o "[0-9\-]+$" but this only works when my backup disk is plugged in. If not, i get the error message Unable to locate machine directory for host.

Is there any other way to figure out (through scripting) when the last backup was made?

I'm running OS X Mavericks and the use case would be to eventually run this as remote monitoring for Macs, say, using collectd.

Best Answer

Parse the XML you get from settings - defaults read on the command line:

defaults read /Library/Preferences/com.apple.TimeMachine.plist Destinations | tail -4 |head -1

That is a crude way to parse the xml / plist so you could use python or swift to properly read the preference plist / xml and parse out things like the last local snapshot date, last consistency check date, etc...

defaults read /Library/Preferences/com.apple.TimeMachine.plist Destinations