Posted on 10-25-2013 10:28 AM
Apple has changed where Time Machine data is stored in the latest OS and how that data is organized. I've modified the original JAMF Extension Attribute to accommodate Apple's changes in Mavericks. The XML is ready for upload. I've only tested this in the Casper Suite 9.2 but it should work fine in any version that supports Extension Attributes.
https://dl.dropboxusercontent.com/u/874171/TimeMachineLastBackupCompleted.xml.zip
Cheers,
Chad Nielsen
Forget Computers
Solved! Go to Solution.
Posted on 01-22-2014 04:53 AM
hy chad,
thanx for the script, but in 10.9.1 it didn't worked correctly, because the parameter lastBackupTime was not the right date. it took the first ever made backup-timestamp and not the latest.
Working with Casper 9.21 & OS X Mavericks 10.9.1
I patched the script. watch below: cheers Rémy
#!/bin/sh
# Gather Time Machine Last Backup Status for JSS
# Written by Chad Nielsen
# Forget Computers, Get Creative!
# Last Modified on October 25th, 2013.
# Updated by Rémy Schwarz on January 22th, 2014 / Habegger AG
# Version History
# 1.0 - original attribute by JAMF Software supporting OS X 10.8 and lower.
# 1.1 - added ability to check status in OS X 10.9 Mavericks.
# 1.2 - Optimized the Command to find the latest TimeMachine-Backup-date on OS X 10.9 Mavericks.
# Determine the OS Version
OS=$(sw_vers | awk '/ProductVersion/{print substr($2,1,4)}')
# Check the OS, and then check the values in the appropriate corresponding files.
if [ "$OS" = "10.9" ]; then
# Check to see if autobackup is enabled.
autoBackupEnabled=$(defaults read /Library/Preferences/com.apple.TimeMachine | awk '/AutoBackup/{print $3}' | tr -d ";")
# A value of 1 signifies that Time Machine is on, a value of 0 is off.
if [ "$autoBackupEnabled" = "1" ]; then
#lastBackupTime=$(defaults read /Library/Preferences/com.apple.TimeMachine | awk '/SnapshotDates/{getline; print substr($0,9)}' | sed 's/^ *//g' | tr -d '"')
lastBackupTime=$(defaults read /Library/Preferences/com.apple.TimeMachine Destinations | sed -n '/SnapshotDates/,$p' | grep -e '[0-9]' | awk -F '"' '{print $2}' | sort | tail -n1 | cut -d" " -f1,2)
else
lastBackupTime="Not enabled."
fi
else
# This is the traditional attribute code provided by JAMF, modified slightly.
if [ -f /private/var/db/.TimeMachine.Results.plist ]; then
lastBackupTime=$(defaults read /private/var/db/.TimeMachine.Results "BACKUP_COMPLETED_DATE")
else
lastBackupTime="Not enabled."
fi
fi
# Report the Time Machine status to the JSS.
echo "<result>$lastBackupTime</result>"
Posted on 12-19-2013 06:56 AM
Hi Chad,
Thanks for posting this extension. However I"m not able to get this to work with Casper 9.22
Inventory displays either Not Enabled or blank. Any ideas?
Thanks! Corbin
Posted on 12-20-2013 10:28 AM
Thanks! It's working for me in version 9.22. Had to recon the computer twice for it to update though.
Posted on 12-20-2013 12:15 PM
I deleted the extension and then re-download from the github link. After uploading, I"m starting to see results in inventory and a smart group. Thanks!
Posted on 01-22-2014 04:53 AM
hy chad,
thanx for the script, but in 10.9.1 it didn't worked correctly, because the parameter lastBackupTime was not the right date. it took the first ever made backup-timestamp and not the latest.
Working with Casper 9.21 & OS X Mavericks 10.9.1
I patched the script. watch below: cheers Rémy
#!/bin/sh
# Gather Time Machine Last Backup Status for JSS
# Written by Chad Nielsen
# Forget Computers, Get Creative!
# Last Modified on October 25th, 2013.
# Updated by Rémy Schwarz on January 22th, 2014 / Habegger AG
# Version History
# 1.0 - original attribute by JAMF Software supporting OS X 10.8 and lower.
# 1.1 - added ability to check status in OS X 10.9 Mavericks.
# 1.2 - Optimized the Command to find the latest TimeMachine-Backup-date on OS X 10.9 Mavericks.
# Determine the OS Version
OS=$(sw_vers | awk '/ProductVersion/{print substr($2,1,4)}')
# Check the OS, and then check the values in the appropriate corresponding files.
if [ "$OS" = "10.9" ]; then
# Check to see if autobackup is enabled.
autoBackupEnabled=$(defaults read /Library/Preferences/com.apple.TimeMachine | awk '/AutoBackup/{print $3}' | tr -d ";")
# A value of 1 signifies that Time Machine is on, a value of 0 is off.
if [ "$autoBackupEnabled" = "1" ]; then
#lastBackupTime=$(defaults read /Library/Preferences/com.apple.TimeMachine | awk '/SnapshotDates/{getline; print substr($0,9)}' | sed 's/^ *//g' | tr -d '"')
lastBackupTime=$(defaults read /Library/Preferences/com.apple.TimeMachine Destinations | sed -n '/SnapshotDates/,$p' | grep -e '[0-9]' | awk -F '"' '{print $2}' | sort | tail -n1 | cut -d" " -f1,2)
else
lastBackupTime="Not enabled."
fi
else
# This is the traditional attribute code provided by JAMF, modified slightly.
if [ -f /private/var/db/.TimeMachine.Results.plist ]; then
lastBackupTime=$(defaults read /private/var/db/.TimeMachine.Results "BACKUP_COMPLETED_DATE")
else
lastBackupTime="Not enabled."
fi
fi
# Report the Time Machine status to the JSS.
echo "<result>$lastBackupTime</result>"
Posted on 01-22-2014 06:15 AM
Cool!
Posted on 03-25-2014 01:53 PM
Nicely done, Rémy! Thanks for posting the updated script!
Cheers,
Chad
Posted on 03-26-2014 05:33 AM
and I'll take one of these...
Nice work!
Posted on 04-01-2015 06:59 PM
Thanks for this!
Here's another, which returned days (integer) since last successful Time Machine backup. Useful because you can do integer comparisons and catch Macs that haven't backed up x + days.
doesn't work with multiple destinations, rather untested... feel free to improve.
Posted on 06-04-2015 01:25 PM
Do we know if this works with 10.10.x? Thanks
Posted on 06-04-2015 03:11 PM
I know mine does. Running across my fleet from 10.7-10.10
Posted on 06-05-2015 05:36 AM
Here's another version of his updated extension attribute.
#!/bin/sh
# Gather Time Machine Last Backup Status for JSS
# Written by Chad Nielsen
# Forget Computers, Get Creative!
# Last Modified on October 25th, 2013.
# Updated by Rémy Schwarz on January 22th, 2014 / Habegger AG
# Version History
# 1.0 - original attribute by JAMF Software supporting OS X 10.8 and lower.
# 1.1 - added ability to check status in OS X 10.9 Mavericks.
# 1.2 - Optimized the Command to find the latest TimeMachine-Backup-date on OS X 10.9 Mavericks.
# 1.3 - Stolen from Chad Nielsen and shamelessly modified to report lastbakup from 10.10 Yosemite. I'm darned sure there's a better way to handle the version check but I had very little time. Sorry Chad
# Determine the OS Version
OS=$(sw_vers | awk '/ProductVersion/{print substr($2,1,4)}')
# Check the OS, and then check the values in the appropriate corresponding files.
if [ "$OS" = "10.9" ]||[ "$OS" = "10.1" ]; then
# Check to see if autobackup is enabled.
autoBackupEnabled=$(defaults read /Library/Preferences/com.apple.TimeMachine | awk '/AutoBackup/{print $3}' | tr -d ";")
# A value of 1 signifies that Time Machine is on, a value of 0 is off.
if [ "$autoBackupEnabled" = "1" ]; then
#lastBackupTime=$(defaults read /Library/Preferences/com.apple.TimeMachine | awk '/SnapshotDates/{getline; print substr($0,9)}' | sed 's/^ *//g' | tr -d '"')
lastBackupTime=$(defaults read /Library/Preferences/com.apple.TimeMachine Destinations | sed -n '/SnapshotDates/,$p' | grep -e '[0-9]' | awk -F '"' '{print $2}' | sort | tail -n1 | cut -d" " -f1,2)
else
lastBackupTime="Not enabled."
fi
else
# This is the traditional attribute code provided by JAMF, modified slightly.
if [ -f /private/var/db/.TimeMachine.Results.plist ]; then
lastBackupTime=$(defaults read /private/var/db/.TimeMachine.Results "BACKUP_COMPLETED_DATE")
else
lastBackupTime="Not enabled."
fi
fi
# Report the Time Machine status to the JSS.
echo "<result>$lastBackupTime</result>"
Posted on 02-23-2016 12:39 AM
Hi Chris,
Many thanks for the scripting..
Could you tell me what the difference is between the command for 10.9 and the one for 10.10 ? I cannot see any difference and both command work on my 10.10.5 test machine (I just ran the lastbackuptime ommand manually)
Posted on 02-23-2016 04:07 AM
Nothing is different in the command. The script was just modified to allow 10.10 as a valid OS. I'm more of a hack and slash script pirate, but none of this work is mine.
if [ "$OS" = "10.9" ]||[ "$OS" = "10.1" ]; then
vs
if [ "$OS" = "10.9" ]; then
There was a good discussion about this and other TM EAs over here where @mm2270 helps point us in better scripting directions https://jamfnation.jamfsoftware.com/discussion.html?id=13289. As @mm2270 points out you could also use something like
if [ "$OS" -ge "9" ]; then
as it would pass any OS 9 or higher.
Posted on 02-24-2016 12:38 AM
ok,
:) I guessed the check command itself was the same :) Thanks for the reply.
Posted on 11-17-2022 05:23 AM
Any updates for Ventura? Apple's moved the location of the pathPlistOld - can't locate them to update the script