check TimeMachine backup status

User avatar
kw123
Posts: 8705
Joined: Sun May 12, 2013 4:44 pm
Location: Dallas, TX
Contact:

check TimeMachine backup status

Post by kw123 »

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 (<====)
User avatar
kw123
Posts: 8705
Joined: Sun May 12, 2013 4:44 pm
Location: Dallas, TX
Contact:

Re: check TimeMachine backup status

Post by kw123 »

updated script to set output format of date time stamp (v2. first post)
User avatar
kw123
Posts: 8705
Joined: Sun May 12, 2013 4:44 pm
Location: Dallas, TX
Contact:

Re: check TimeMachine backup status

Post by kw123 »

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 3033 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
Post Reply

Return to “Karl's Plugins and Scripts”