-
Notifications
You must be signed in to change notification settings - Fork 0
Backup
Backup as it name suggests provides functionality to backup my Home Assistant system. I use the Autobackup integration which provides all the functionality needed. (Link to Github). This allows you to define time patterns for backups and what to backed up. In mine I have generally followed the recommendations of the author, a partial backup every 6 hours, this takes care of any changes I make to code. A Daily backup which is kept for 7 days and finally a weekly backup which is kept for 28 days. This ensures there is always a backup available for any disasters that may occur. The trigger in each case is time. Using conditions to define which days of the week and in the action which parts of Home Assistant are backed up.
Captures a partial backup every six hours and keeps for 2 days. This only stores changes to Homeassistant.
trigger:
platform: time_pattern # Perform backup every 6 hours.
hours: "/6"
action:
service: auto_backup.backup_partial # Only perform a partial backup to save storage.
data:
name: "Partial_Backup: {{ now().strftime('%a, %-I:%M %p (%d/%m/%Y)') }}"
addons:
# - core_mariadb
folders:
- homeassistant
# - share
keep_days: 2`
This backup is created daily for all folders in Home Assistant, it is completed every day bar Mondays as the weekly backup is done Monday. Daily backups are automatically kept for 7 days, at the end of which they are automatically deleted.
`trigger:`
`platform: time`
`at: "02:30:00"`
`condition:`
`condition: time `
`weekday: # daiy backup except Monday when weekly backup is completed`
`- tue`
`- wed`
`- thu`
`- fri`
`- sat`
`- sun`
`action:`
`- service: auto_backup.purge`
`- service: auto_backup.backup_full`
`data:`
`name: "DailyBackup: {{ now().strftime('%A, %B %-d, %Y') }}"`
`keep_days: 7`
This, as the name suggests, creates a full backup once per week which is then stored for 28 days. By overlapping the backups, in theory, it should minimise the risk of any changes being losted through server failure or SSD failure. The automation also purges expired backups to clean up the storage.
`trigger:
platform: time
at: "02:30:00"
condition:
condition: time # On Mondays remove expired backups & perform a weekly backup
weekday:
- mon
action:
- service: auto_backup.backup_full
data:
name: "WeeklyBackup: {{ now().strftime('%A, %B %-d, %Y') }}"
keep_days: 28 # Store backup for a month, basically perform 1 backup each week and store for 4 weeks.
- service: auto_backup.purge`
This automation checks of any notification of backup failure and notifies via the Home Assistant messages that the back has failed. This is triggered by an event rather than time.
`trigger:
platform: event
event_type: auto_backup.backup_failed
action:
service: persistent_notification.create
data:
title: "Backup Failed."
message: "Name: {{ trigger.event.data.name }}\nError: {{ trigger.event.data.error }}"`
None
The backups are currently stored within the Home Assistant server, with copies taken to a NAS for extra security. I originally intended to use rsync to do this automatically but currently re-evaluating this as an option or whether to back up to an external store such as Amazon S3 or Dropbox.
copyright rjenx (c) 2022 HomeAssistant_Public