Time machine backups

It would be nice to be able to have time machine backups from HomeAssistant.

What do you mean? It already has snapshots.

I don’t mean to back up homeassistant - I mean to have a container that I can set up which takes care of the backups of the computers on the network - do you know Time machine?

It’s an Apple thing. I don’t use Apple stuff, but I know it is a backup system. Do you mean you want Home Assistant to store a backup of all of the computers?

Well, something that would be managed on homeassistant and kept on an external volume. I think I will play with it.

I’m also interested in this - I’m currently running a TM service in docker, but am contemplating building an add-on to better integrate with HA (need to learn more about add ons first!)
For reference, this is the image I’m using: https://github.com/odarriba/docker-timemachine

All you Need is a Samba share where you put a sparse bundle on (that you can create with Mac disk utility).
Google time machine smb

What would be more interesting than HA doing backups (TM does it well), would be to have HA monitoring the TM backup on the Samba share to verify backups are happening and warning if not.

I’ve got this setup, but it depends on what device you store your TM backups on.

I’ve got my TM backup setup on a linux SMB share. I cron a script to check the com.apple.TimeMachine.MachineID.plist file for the verification integer. Based on this result, the script updates a HA sensor via the API with ‘normal’ or ‘error’.

Happy to share my script and how I do it if you want.

Hi Anton

I would be very interested in how you monitor the TM from HA. Thanks for sharing

Hi Roger. I cron a script which checks the verification integer in the Time Machine folder and posts it to home assistant. Code below is for the script to run on the linux SMB share device hosting the Time Machine:

#!/bin/bash

#check integer value for verifcation status in MachineID.plist file 
#Then update home assistant

#HA setup
#1)Setup long lived key in Home assistnat
#2)Setup input_text sensor

#Constant variables (do not change)
NOW_DATE=$(date "+%F %T")

#Variables to change

#Path to location of MachineID.plist file (remember to escape)
TM_1= #folder of MachineID.plist

#Home Assistant long lived key, IP address and input_text sensor name
KEY= #long lived key
HA_IP= #IP address of Home Assitant without port number
HA_sensor= #name of input_text sensor without input_text.

#Determine integer value from MachineID.plist file for each TM backup
STATE_TM_1=$(cat "$TM_1"/com.apple.TimeMachine.MachineID.plist | grep '<integer>' | sed 's@<.*>\(.*\)</.*>@\1@g')

#Set variable to be posted to Home Assistant based on integer value
if [ $STATE_TM_1 = 2 ]; then
        TM_1=error
elif [ $STATE_TM_1 = 0 ]; then
        TM_1=normal
elif [ $STATE_TM_1 = 1 ]; then
        TM_1=normal
elif [ $STATE_TM_1 = 4 ]; then
        TM_1=normal
else
        TM_1=check
fi

#CURL status to Home Assistant, inlcude date and time posted to ensure sensor
#is being updated correctly.
 
curl -X POST -H "Authorization: Bearer $KEY" \
-H "Content-Type: application/json" \
-d '{"state": "'$TM_1'", "attributes": {"last_update": "'"$NOW_DATE"'"}}' \
http://$HA_IP:8123/api/states/input_text.$HA_sensor \
> /dev/null

Remember to set up a ‘long lived key’ and copy that from home assistant into the script. You also needs to setup an input_text helper where the check information is placed in home assistant. You’ll now have a sensor which you can setup alerts, etc.

Hope this helps.