Lastest (Last) Time Machine Backup (Date) - Mac and TM Drive

Steven5342
New Contributor III

This is for finding a Time Machine Backup time for devices on 10.13 and up. (As far as I tested). I always had trouble getting the most recent backup time as the Extension Attributes in Jamf appear "Out of Date". So here are my findings for anyone who ran into this problem as I have and could not find anything out there in Jamf Nation.

This script reads from the Plist on the Mac itself:

#!/bin/sh
enabled=/usr/bin/defaults read /Library/Preferences/com.apple.TimeMachine AutoBackup
if [ "$enabled" == "1" ];then
lastBackupTimestamp=date -j -f "%a %b %d %T %Z %Y" "$(/usr/libexec/PlistBuddy -c "Print Destinations:0:SnapshotDates" /Library/Preferences/com.apple.TimeMachine.plist | tail -n 2 | head -n 1 | awk '{$1=$1};1')" "+%Y-%m-%d %H:%M:%S"
echo "<result>$lastBackupTimestamp</result>"
else
echo "<result>Disabled</result>"
fi

This script reads from the Time Machine Drive if it is plugged in (should be in Jamf EA):

#!/bin/sh
backupDate="$(tmutil latestbackup)"
trimmedbackupDate="${backupDate: -15}"
Echo "<result>$trimmedbackupDate</result>"

More information/source can be found with this link:

Click Here

0 REPLIES 0