Skip to main content
Solved

Time Machine Extension Attribute for OS X 10.9 Mavericks

  • October 25, 2013
  • 15 replies
  • 20 views

Forum|alt.badge.img+14

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

Best answer by it_services

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

15 replies

Forum|alt.badge.img+11
  • Valued Contributor
  • 164 replies
  • December 19, 2013

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


Forum|alt.badge.img+7
  • Contributor
  • 50 replies
  • December 20, 2013

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


Forum|alt.badge.img+11
  • Valued Contributor
  • 164 replies
  • December 20, 2013

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!


Forum|alt.badge.img+4
  • New Contributor
  • 1 reply
  • Answer
  • January 22, 2014

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

Forum|alt.badge.img+11
  • Valued Contributor
  • 164 replies
  • January 22, 2014

Cool!


Forum|alt.badge.img+14
  • Author
  • Contributor
  • 21 replies
  • March 25, 2014

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

Cheers,
Chad


Chris_Hafner
Forum|alt.badge.img+25
  • Jamf Heroes
  • 1754 replies
  • March 26, 2014

and I'll take one of these...

Nice work!


loceee
Forum|alt.badge.img+10
  • Contributor
  • 182 replies
  • April 2, 2015

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.


Forum|alt.badge.img+8
  • Contributor
  • 50 replies
  • June 4, 2015

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


loceee
Forum|alt.badge.img+10
  • Contributor
  • 182 replies
  • June 4, 2015

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


Chris_Hafner
Forum|alt.badge.img+25
  • Jamf Heroes
  • 1754 replies
  • June 5, 2015

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

Forum|alt.badge.img+8
  • Contributor
  • 118 replies
  • February 23, 2016

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
Forum|alt.badge.img+25
  • Jamf Heroes
  • 1754 replies
  • February 23, 2016

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.


Forum|alt.badge.img+8
  • Contributor
  • 118 replies
  • February 24, 2016

ok,

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


Forum|alt.badge.img
  • New Contributor
  • 1 reply
  • November 17, 2022

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