đź’ľ Create Automated Backups Every Day

This automation blueprint will create automated backups every day, and optionally send a notification to the official Home Assistant mobile app.

Blueprint

Click the badge to import this Blueprint: (needs Home Assistant Core 2021.3 or higher)

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Or you can import this Blueprint by using the forum topic URL:

blueprint:
  name: Automated Daily Snapshot
  description: Create a full snapshot backup at a given time every day.
  domain: automation
  input:
    trigger_time:
      name: Snapshot creation time
      description: The snapshot will be created at this time, every day
      selector:
        time:
    send_notification:
      name: Send notification
      description: Sends a notification to a device if enabled
      selector:
        boolean:
      default: false
    notify_device:
      name: Device to notify
      description: Device needs to run the official Home Assistant app to receive notifications
      selector:
        device:
          integration: mobile_app
      default: ""

mode: single
max_exceeded: silent

variables:
  backup_filename: "Automated backup {{ now().strftime('%F') }}"
  send_notification: !input send_notification
  notify_device: !input notify_device
  notification_title: Automated Daily Backup
  notification_message: "Home Assistant full backup created. {{ now().strftime('%F') }}"

trigger:
  - platform: time
    at: !input trigger_time

action:
  - service: hassio.snapshot_full
    data:
      name: "{{ backup_filename }}"

  - choose:
      - conditions: "{{ send_notification }}"
        sequence:
          - device_id: !input notify_device 
            domain: mobile_app
            type: notify
            title: "{{ notification_title }}"
            message: "{{ notification_message }}"

Importing Blueprint:
https://community.home-assistant.io/t/about-blueprints

15 Likes

This is only half the task. You need to get those backups off the home assistant server in case of storage corruption. For which these addons are a better option:

To a NAS: Samba Backup: Create and store snapshots on a Samba share

To Goggle Drive: Hass.io Add-on: Hass.io Google Drive Backup

To DropBox: Hass.io Add-on: Upload hassio snapshots to Dropbox

To NextCloud: [New Addon] Snap-Shipper - Webdav backups (and probably other ways to later on)

24 Likes

13 posts were split to a new topic: Split blueprint discussion

I copied and modified this blueprint to take zfs snapshots on my TrueNAS server. Details are OT but this simple blueprint combined with a rest_command allows me to easily reproduce the same automation on different datasets. It’s very simple and that’s why I like it.

I can see simple blueprints being attractive to new users who don’t want to yaml

3 Likes

Let’s not make this topic a discussion about blueprints, let’s keep it about the automated backup blueprint

2 Likes

Good point. I flagged my first post and asked the mods to split it, and all subsequent posts about blueprints, to a separate topic.

Hi, would it be possible to make a blueprint where you could select the frequency and partial items of teh snapshot. instead of full and daily. Like weekly and partial with selection of the partial items.

Frequency: With the current selectors (input types) it is possible to do with toggles for every day (like in the Time condition on the Automations UI). I hope we will have a built-in selector for this in the future, so this would be easier.

Partial snapshot: there is the hassio.snapshot_partial service, but you have to define the parameters with optional lists which seems complicated.

1 Like

Would it be possible to only take a snapshot if something changed?

I don’t make changes that often, and it would be annoying to have to keep deleting daily snapshots for the times when nothing changed.

Or to write the snapshot to a NAS or google drive if something changed, then delete the snapshot.

Randy

No. You’d need something to indicate to HA that something changed in the config. No built in solutions for that exist.

I think it can be done with Folder watcher and something like an input_boolean, which turns on if there was a change in the config during the day and resets every day.

1 Like

You could use the Samba Backup add-on to automate the managemt of Snapshot.

Yep, didn’t realize that integration is recursive. You don’t need an input boolean, just use a trigger based on the modified event and created event.

trigger:
  - platform: event
    event_type: folder_watcher
    event_data:
      event_type: modified
  - platform: event
    event_type: folder_watcher
    event_data:
      event_type: created

I don’t want to create a snapshot every time I hit save, that’s why I suggested to store that “config changed today” in an input_boolean.

1 Like

Nice idea! One gotcha though, if you are going to watch the full /config folder with folder watcher make sure events for modifications to the db file and log are excluded.

The DB is the biggest problem since it updates so much. For anyone that uses the MariaDB add-on this isn’t an issue but if using the out of the box configuration the entire DB is a file in /config. I made this mistake once and almost fried my CPU before I realized what had happened. Made me very glad I had set up alerts for the CPU temperature rising too high.

Sadly that’ll make it a bit tricky to implement in practice since you can only provide inclusion patterns to folder watcher. There’s a lot of random subfolders created by integrations and things and it doesn’t help that many of the files (including all the ones in .storage) have no extension so its tough to make an inclusion filter for them.

Really need an “exclude this file/pattern” option.

1 Like

Sound good. For the schedule I will try to use the scheduler card to turn on and off the automation. For the partial backup that was more a nice to have.

Can a database stop be added so the database is stopped prior to the snapshot and restarted after it completes? I just found out that the add on snapshot to google drive allows the db to be stopped prior to the backup. This is needed to prevent a db corruption. I just did a snapshot and restore to a new device and this works. Also the add-on can be schedule so I’m not sure the need of this blueprint.

Hi @vorion,

thank you so much for this really helpful blueprint! :fire:

I’m kickstarting a small project which aims to create a curated collection of reliable, documented and high quality blueprints, which could eventually become a valuable resource both for Home Assistant newcomers and experienced users.

I published Awesome HA Blueprints as a website which can be easily browsed, but the codebase, including the list of blueprints, is available in this GitHub repository . The project is still in its early stages but I hope many blueprints will be added in the upcoming weeks and months.

Here’s the original thread:

It would be amazing to have this blueprint in the collection.
If you’ve time and you’re interested in contributing and helping the project, it would be great if you could submit your blueprint by opening a Pull Request there. Also, I could take care of adding it to the list if you’d like to.
Just let me know. :+1:

Thank you for your time! :fire:

1 Like

Sorry for maybe a stupid question, but when I run this script (automation) i got this error:

Unable to find service hassio.snapshot_full

Any clue? I didn’t found a way how to add this service.
PS: Running HA via Balena… maybe this service is missing in this distro?

Thanx a lot!
Maxim

Can this Blueprint be updated for next HA release?
snapshot_full is replaced by backup_full :wink: