Skip to content

Instantly share code, notes, and snippets.

@cogneato
Last active December 1, 2022 06:44
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cogneato/24d5a1a0daddec9d048048201170df8b to your computer and use it in GitHub Desktop.
Save cogneato/24d5a1a0daddec9d048048201170df8b to your computer and use it in GitHub Desktop.

Home Assistant OS Snapshots

Snapshots are easily made in Home Assistant OS and are a service that can be automated. These can be made from the UI or the CLI (see below). They are stored in the /backup directory. Having snapshots handy will make it much easier on yourself. You can make changes without fear!

A full snapshot includes the following directories:

  • config
  • share
  • addons (the manually installed or created addons)
  • ssl

They also include a gzip file for each installed addon which contains the addon's version, config settings, and other data if any.

Making a Snapshot

  1. Go to Supervisor > Snapshots in the UI
  2. Provide a name for the snapshot.
  3. Choose full or partial.
  4. Choose to password protect or not.

Warning - Password protected snapshots cannot easily be browsed outside of Home Assistant OS

  1. The only progress indicator at the moment is via the logs at the Supervisor > System page in the UI (or ha su logs in the CLI).
  2. To update the snapshots page in order to see current snapshots, use the reload icon in the upper right of the page.

Restoring a Snapshot on a new install

Restoring a snapshot on a fresh install of Home Assistant OS requires that you upload the snapshot to it. There is no way to upload snapshots from the snapshot dashboard at this time so the first thing to do is install and configure an addon of your preference. Samba, Configurator, or IDE are all good choices for this.

After uploading to the backup directory, visit the snapshot page in the UI and reload the page using the icon in the upper right of the page to make the uploaded files visible. From there you can select your snapshot, choose a full or partial install and choose restore.

Note: Before restoring third-party addons, add their repositories to the addon store page first! These are any addons which are not in the official repo or the community addon repo. Nothing bad will happen, but those addons won't get restored. You can always add the repos and then go back and do a partial restore of the missing addons.

How long do snapshots take? How long do they take to restore?

As long as a piece of string, as they say. The length of time it takes will depend on how much you have to compress or decompress. Large db files are the usual cause (the default db is home-assistant_v2.db found in config) and will take a long time to deal with on any of the pis.

TIP: The db files don't always restore well and you may need to delete the restored db altogether if you experience errors or wonky behavior. If you really want to keep long term historical data, look into offloading it to another machine/database that is more hardy.

See the recorder component page for ways to keep your db data down to a size that won't cause issues. Note the keep days, purge interval, and include/exclude options. https://www.home-assistant.io/components/recorder/

When the restore is complete, you will lose connection to the UI and it will return just as though you had restarted Home Assistant. It can be a good idea to do an additional full reboot as well especially if addons appear to be missing from the restore. You can reboot from the Supervisor > System > Host System page.

Can I use the cli to make or restore snapshots?

YES! You can use the following:

  1. ha sn list to list snapshots and their slugnames
  2. ha sn restore slugname to restore a snapshot
  3. ha sn new --name nameofsnapshot to create a snapshot

Use ha help to see more info.

More automation and usage examples here

Remove your snapshots to another location!

The snapshots will do you no good if they are on the device which you cannot access! Copy them off in batches manually from /backup on occasion. Or even better, make use of an addon like Google Drive backup or Dropbox Sync and automate it!

Hass.io Google Drive Backup

Dropbox Sync

Remote Backup (uses scp)

@adebree
Copy link

adebree commented Jul 28, 2020

Samba backup is also a nice Add on to copy snapshots automatically to a remote Samba share:

https://github.com/thomasmauerer/hassio-addons/tree/master/samba-backup

@cogneato
Copy link
Author

@adebree I hardly visit this page and just now saw this. Thanks! Not only that, I think I saw it mentioned in the Month of WTH somewhere today too. I'll check it out.

@PD5DJ
Copy link

PD5DJ commented Jan 19, 2021

Nice feature, but how on earth do I know which back contains what?
The random file name makes it almost useless to use.
Please add date and time stamp in the tar file name.

@jdwhite
Copy link

jdwhite commented May 8, 2021

Nice feature, but how on earth do I know which back contains what?

Each snapshot tarball contains a ./snapshot.json file which contains the on-storage name (called the "slug"), name as it appears in the Snapshots Web UI, date taken, metadata regarding addons, folders backed up, and other info. It's not convenient, but it's there and stored unencrypted even with password protected backups.

@jdwhite
Copy link

jdwhite commented May 8, 2021

Another way using the Terminal/SSL add-on from a shell using ha snapshots:

# ha snapshots
snapshots:
- date: "2021-05-08T19:09:12.569098+00:00"
  name: pass protected full snap
  protected: true
  slug: a7fd7ee2
  type: full
- date: "2021-05-08T18:56:54.943162+00:00"
  name: Automated Backup 2021-05-08 13:56
  protected: false
  slug: 0cf3006e
  type: full

@Ramblurr
Copy link

The Remote Backup addon is now maintained here https://github.com/ikifar2012/ha-addons

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment