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

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:

enabled=/usr/bin/defaults read /Library/Preferences/ 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/ | tail -n 2 | head -n 1 | awk '{$1=$1};1')" "+%Y-%m-%d %H:%M:%S"
echo "<result>$lastBackupTimestamp</result>"
echo "<result>Disabled</result>"

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

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

More information/source can be found with this link:

Click Here