Time Machine Extension Attribute for OS X 10.9 Mavericks

themacallan
New Contributor III

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

1 ACCEPTED SOLUTION

it_services
New Contributor

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>"

View solution in original post

15 REPLIES 15

corbinmharris
Contributor

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

jimlee
New Contributor III

Thanks! It's working for me in version 9.22. Had to recon the computer twice for it to update though.

corbinmharris
Contributor

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!

it_services
New Contributor

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>"

corbinmharris
Contributor

Cool!

themacallan
New Contributor III

Nicely done, Rémy! Thanks for posting the updated script!

Cheers,
Chad

Chris_Hafner
Valued Contributor II

and I'll take one of these...

Nice work!

loceee
Contributor

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.

timemachine_days.sh

doesn't work with multiple destinations, rather untested... feel free to improve.

kyoung
Contributor

Do we know if this works with 10.10.x? Thanks

loceee
Contributor

I know mine does. Running across my fleet from 10.7-10.10

Chris_Hafner
Valued Contributor II

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>"

rblaas
Contributor II

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)

Chris_Hafner
Valued Contributor II

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.

rblaas
Contributor II

ok,

:) I guessed the check command itself was the same :) Thanks for the reply.

rabarar
New Contributor

Any updates for Ventura? Apple's moved the location of the pathPlistOld - can't locate them to update the script