I run Home Assistant as a Docker container on my Unraid server, and that matters for backups: the official docs treat Home Assistant OS and the container differently, and most tutorials you find are written for the OS. This guide sets up automatic backups on a container install, saves the key you need to open them, sends a notification to your phone when one fails, gets a copy off the box and ends with a restore test. It also covers the one error that catches people on the default database, and what to check first when a backup fails.
- Time
- 12 min
- Steps
- 8
- Updated
- 22 Nov 2026
You will learn
- What a container backup contains
- Set up automatic backups
- Pick a good time
- Get told when it fails
- Get a copy off the box
Step 1 of 8: What a container backup contains
Backups in Home Assistant are encrypted by default and saved as a compressed .tar file. On a container install they live in the backups folder inside your configuration directory, in the folder you mapped to /config. That is the first thing to know, because it means the backups sit next to the thing they protect.

# the part of a compose file that matters here
services:
homeassistant:
image: ghcr.io/home-assistant/home-assistant:stable
volumes:
- /path/to/ha-config:/config # backups end up in /config/backups
The docs say a container backup holds the Home Assistant settings (the config folder and your SSL certificates) and, if you choose, the history. Apps, the media and share folders and network storage exist only on Home Assistant OS, so you will not see those options. Some things never go in a backup: log files, caches, and the files in the backups and tmp_backups folders, so a backup never swallows the older ones.
One more exclusion matters if you use a separate database. When the recorder writes to MariaDB or PostgreSQL on another system, that database is not part of the backup. The docs say to back it up separately with the database’s own tools. If you never changed the recorder, you are on the default SQLite database inside the config folder and the history is covered when you include it.
The picture below shows where everything goes, including the alarm we are going to build in step 3.

Step 2 of 8: Set up automatic backups
This is all in the interface. Go to Settings, System, Backups and select Set up backups. The first step is the encryption key.
- Under Download emergency kit, select Download and store the file somewhere safe: a password manager, or a USB stick in a drawer. The key in it is needed to restore any of these backups.
- Choose Recommended if you want the defaults: a daily backup, the last 3 kept, stored on this system (and on Home Assistant Cloud when you are logged in). Choose Custom to set your own schedule.
- With Custom, pick the schedule, the time and the retention. Retention is a number of backups or a number of days. It deletes only automatic backups; manual ones stay.
- On the data step, decide whether to include the history. The docs suggest leaving big things out to keep the backup small, because a big backup also takes longer to restore.
- Pick the locations and select Save and create backup. The first backup is made right away.
To see or change this later, open the same page and use Configure backup settings on the Automatic backup card. The Encryption key card on that page lets you download the emergency kit again. If you ever change the key, keep the old kit: the docs say Home Assistant no longer has the old key, and a backup made with it needs it.

Think about where you keep that kit. The docs point out that the current key is also stored on the affected storage, so if you replace the storage before you have saved the key, you cannot restore backups that use it. The emergency kit in the same folder as the backups is no emergency kit at all.


Step 3 of 8: Pick a good time
The default time is called System optimal. Home Assistant picks a moment after it has cleaned its database, which the docs put between 04:45 and 05:45. That sounds clever, and it is the cause of the one failure I would warn you about.

Before it backs up, the recorder stops writing to its database so the copy is complete. If it is still busy after 30 seconds, the backup fails with Could not lock database within 30 seconds. By default the recorder cleans up old data every night at 04:12 and repacks the database on the second Sunday of each month, so a long repack can still be running when the backup wants to start. The docs also name a big database and slow storage (a USB stick as data disk, for example) as causes. This only happens with the SQLite default; with MariaDB or PostgreSQL the database is not locked.
If you see it, the docs’ fix is simple: wait a few minutes and try again, and if automatic backups keep failing, move them. Under Configure backup settings, set Time to Custom and pick a time later in the day. If it still fails, make the database smaller: keep fewer days of history with the recorder’s purge_keep_days (the default is 10 days), or exclude entities that change constantly. The Estimated database size is under Settings, System, Repairs, System information, in the Recorder section.

The recorder is the part of Home Assistant that writes every state change and event to the database. The diagram from the Home Assistant docs shows why it has to pause for a moment before a backup.

Step 4 of 8: Get told when it fails
A backup that fails quietly is worse than none, because you think you have one. Home Assistant gives you an event entity for this, event.backup_automatic_backup, and it has an attribute with the reason. The docs have the whole automation as an example. In the UI it looks like this:

- Settings, Automations & scenes, Create automation.
- Trigger: Event received. Target: the entity Automatic backup. Event type: Failed.
- Action: Send a notification message, to your phone’s
notifyservice from the companion app. - Message: the template below.
The last backup failed: {{ state_attr('event.backup_automatic_backup', 'failed_reason') }}


The reason can be a backup agent that is unreachable, an upload that failed or an incorrect password, among others. One quirk: the docs say the backup stage and the failure reason are not saved in the history, so you can only read their current values, in this automation. That is another reason to set it up now, instead of looking for the reason a week later.
An alarm you have never heard might not work, so test it. In the automation editor you can run the actions by hand from the three dots menu of the automation, which sends the notification without a real failure. The message will have an empty reason, but you see that the phone buzzes. The Backup integration also has an action, backup.create_automatic, that creates a backup with your automatic settings; run it from the Actions tab of the developer tools to watch the event entity change from in progress to completed.

The integration also gives you sensors: Backup Manager state, next scheduled automatic backup, last attempted, last successful, and the size of the last successful backup. I’d put last successful and the size on a dashboard. A size that suddenly halves or doubles tells you something changed in what you back up.
If the settings in the interface do not fit what you want, you can also build your own schedule around that same action. The docs give the example of an automation that triggers on a calendar, turns on a NAS, waits until it is online and then starts the backup.

Step 5 of 8: Get a copy off the box
The docs say it plainly: if you only keep backups on the device, you will not get at them easily when the system has crashed. They recommend a copy on another system and, ideally, one off-site.
On a container install there are two simple routes. The first is to download a backup from Show all backups: the three dots menu has Download, and the file is decrypted on the fly. You can also download it encrypted. The second is to copy the files out of the backups folder in your config directory. If you already have a file backup tool on the server, point it at that one folder, not at the whole config directory. The backups are already encrypted, which is useful when the copy goes to someone else’s storage. That makes a European provider an easy choice for the off-site copy.

If you use Home Assistant Cloud, the docs say it stores one backup, the last one you saved there, up to 5 GB. It does not replace a copy of your own.

Two things to check on your own copy. The file should be newer than a day or so, which you can see in the file’s date, and it should not be tiny. If you copy out of the folder with a script, make it skip the temporary files and take only the finished .tar files.

Step 6 of 8: Before you update the container
On Home Assistant OS the interface can make a backup before an update for you. On a container you update by pulling a new image, so nothing in the interface does that for you. I’d take a manual backup first: Settings, System, Backups, Backup now, Manual backup. It is a few clicks, and the docs point out why it matters: an update can convert your database to a new format, or convert the settings of some integrations, and an older version may not be able to read the result. Going back to an older version without a backup does not undo what the newer one changed.

That is also the argument for pinning the image to a version while you are unsure. A stable tag moves under you the day you pull. If you pin a version, the update is something you decide to do, with a backup in hand.
Step 7 of 8: Test a restore before you need one
A backup you have never opened might not work. The test I’d do costs half an hour: start a second Home Assistant container with an empty config folder on a different port, so it does not touch the real one. On its welcome screen, the docs describe Upload backup for restoring during onboarding. Pick the file, enter the encryption key from your emergency kit, and let it restore.
Two things from the docs to expect. The restore takes a while and you must not refresh the page: if you do, you see “Not found”, because the system is shut down and rebuilt from the backup in that time. And afterwards you log in with the username and password you had when the backup was made. When your dashboards and automations are there, you have a backup that works. Delete the test container afterwards, because two instances with the same integrations can compete for the same devices.
The docs write most restore steps with Home Assistant OS in mind and do not call out every difference for the container, which is one more reason to try it on a spare instance first, with your own setup.
After a restore, new backups use the encryption key saved in the restored settings. Download the emergency kit again to be sure you hold the right one.
Step 8 of 8: When a backup fails: what to check
- Could not lock database within 30 seconds. The recorder was busy. Wait and retry, then move the backup time later, as in step 2.
- [Errno 5] I/O error or [Errno 30] Read-only file system. The storage cannot be read or written reliably. The docs list a worn or failing SSD or SD card, an unstable USB cable or adapter, and a network share that is set to read-only or dropped. A backup is often the first thing to fail because it reads and writes so many files. Make sure you have a copy and the key on another device first, then look for the cause. Some errors go away after a reboot.
- The backup location is unavailable. The integration that provides the location is not loaded. Automatic backups skip it until it is back, or until you remove it from the settings.
- The provided encryption key was incorrect. Check which key made the backup. If you changed the key afterwards, you need the emergency kit from before the change. The docs also say this message can show up with a correct key when the file is damaged, because Home Assistant cannot tell the two cases apart.
The docs say a failing storage device is the one to take seriously: if Home Assistant’s own storage is the problem, copy your most recent backup to another device before you do anything else. Home Assistant can still offer the download if it only starts in recovery mode.

