check TimeMachine backup status

Posted on
Sat Apr 08, 2017 4:15 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

check TimeMachine backup status

This script will create 2 variables:

-TM-hours-Since-Last-Backup ==> full hour since last time machine back up finished
-TM-LastBackup ==> time stamp of last backup.

run this script in a schedule (schedule / server/script) every hour and then do a trigger on any change in variable "TM-hours-Since-Last-Backup" : if variable > 1 then backup is older than 2 hours . You then can send yourself an email ...


Code: Select all
import subprocess
import datetime
import time

cmd                   = "/usr/bin/tmutil latestbackup"
statusVariable        = "TM-LastBackup"
hoursSinceLastBackup  = "TM-hours-Since-Last-Backup"
lastBackupFileName    = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).communicate()[0]
formatOfDateStamp     = "%Y-%m-%d %H:%M:%S"  # <==== change this to your liking for the variable that will contain the dateStamp
try: indigo.variable.create(statusVariable)
except: pass
try: indigo.variable.create(hoursSinceLastBackup)
except: pass
if lastBackupFileName!="":
    theDate = lastBackupFileName.split("/")[-1].strip()
    dd      = datetime.datetime.strptime(theDate, "%Y-%m-%d-%H%M%S")
    outpDate= dd.strftime(formatOfDateStamp)
    delta   = int(  time.time() - time.mktime(dd.timetuple())  )/3600
    indigo.variable.updateValue(statusVariable, outpDate)
    indigo.variable.updateValue(hoursSinceLastBackup, unicode(delta))



Karl

v 2:
added variable to setup the format of date stamp in your variable (<====)

Posted on
Fri May 12, 2017 7:01 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: check TimeMachine backup status

updated script to set output format of date time stamp (v2. first post)

Posted on
Sat May 13, 2017 4:43 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: check TimeMachine backup status

you can put this script into the action script window (embedded script) or save it to a file (e.g. ~ documents/tmUtil.py
Screen Shot 2017-05-13 at 17.42.33.png
Screen Shot 2017-05-13 at 17.42.33.png (79.11 KiB) Viewed 2267 times
) and call the script in the action setup.

this is useful if your system is busy and the script in the embedded version times out.

Karl

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 5 guests

cron