Posted on 06-10-2021 12:46 PM
We use network Time Machine to back up our Macs and have them pointed at two different Synology NAS boxes as backup destinations.
To keep an eye on our Macs as they complete (or don't complete) backups, I'm hoping to create an Extension Attribute in Jamf that will show the most recently completed backup. So far I haven't found any scripts that will do this for network Time Machine - only for local Time Machine.
Anyone have any ideas of how I could accomplish this?
Posted on 06-10-2021 12:56 PM
I will list what we use in our environment, they aren't mine, you might've seen them already but I hope they help. I would start with checking your Time Machine .plist & trying to pull info from that.
Time Machine Destination
#!/bin/sh
#TimeMachineDestination
enabled=`/usr/bin/defaults read /Library/Preferences/com.apple.TimeMachine AutoBackup`
if [ "$enabled" == "1" ];then
validateDestination=`/usr/sbin/diskutil info $(/usr/bin/defaults read /Library/Preferences/com.apple.TimeMachine "DestinationVolumeUUID") | awk '{print $1, $2}'`
if [ "$validateDestination" == "Could not" ];then
echo "<result>Destination not mounted</result>"
else
backupDestination=`/usr/sbin/diskutil info $(/usr/bin/defaults read /Library/Preferences/com.apple.TimeMachine "DestinationVolumeUUID") | grep "Mount Point" | /usr/bin/cut -c 30-`
echo "<result>$backupDestination</result>"
fi
else
echo "<result>Not enabled.</result>"
fi
Time Machine Last Backup
#!/bin/sh
# Gather Time Machine Last Backup Status for JSS
# Written by Chad Nielsen
# Forget Computers, Get Creative!
# Last Modified on October 25th, 2013.
# 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.
# 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 '"')
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>"
Time Machine Status
#!/bin/sh
#Time Machine Status
BACKUPS="$(defaults read /Library/Preferences/com.apple.TimeMachine AutoBackup 2> /dev/null)"
if [ "$BACKUPS" == 1 ]
then echo "<result>Enabled</result>"
else echo "<result>Disabled</result>"
fi
Posted on 06-10-2021 01:12 PM
Thanks. Do you all use network based Time Machine in your environment? I tried the "Time Machine Last Backup" and got a "Not enabled." result... 🤔
Posted on 06-10-2021 03:07 PM
So that's my bad for not fully explaining @jmackbnd , no we do not, these extension attributes were created with using a local, physical hard drive in mind. I shared them with the prospect that they would help & that you could change out some of the script & replace pieces, for example, target the time machine plist configurations that see the network drive, etc.
Posted on 06-21-2021 12:55 PM
Thanks @Hugonaut. I found an array in com.apple.TimeMachine.plist that might work. It's located under Destinations/Item 0 and is called SnapshotDates. These are a close match to the backup dates that I'm seeing by simply mounting the network drive in Finder, but not exact for some reason. There are the same number of entries in this array as there are backups on the network drive and the dates on them often match exactly, but sometimes differ by one day. I'm fairly certain that this array is referring to the actual backups on the network drive, though, rather than local snapshots because they're not at all similar to the dates I get when I run tmutil listlocalsnapshotdates.
I'm pretty new to scripting. Assuming this is the correct array to be looking at, can anyone help me figure out how to extract the date from the most recent value in this array? I've included a screenshot of the array for reference.
Posted on 06-24-2021 12:19 PM
Just an update here in case anyone finds this thread. What ended up working for me was the script in this post contributed by @jltrenary on 3/6/2017:
https://www.jamf.com/jamf-nation/discussions/13289/time-machine-extension-attribute-compatible-with-10-10
I had tried using tmutil latestbackup, but as referenced in the thread above that method doesn't work if the Mac isn't currently connected to the Time Machine disk. The solution is to reference the Mac's local plist that contains backup history, which is what the above script does.
It seems to be working great for me on 11.x (Big Sur). It's really great to finally have a way to reference our Mac's most recent backup dates and to build Smart Computer Groups off of that Extension Attribute!