What backup strategy when running Home Assistant in Docker?

This is the type of question you should search before posting, as it has nothing to do with Docker. But yes, the database is definitely part of the backup.

I agree with the idea, but haven’t researched if it’s possible or even less - exactly how to do it.

unfortunately, it doesn’t seem to work here, I don’t really get why it complains about zha_gateway. And on the other hand, I migrated the database from sqlite to pgsql, which I’m already backing up. Perhaps I should do just a rclone/rsync task for the data directory.

homeassistant  | 2024-01-19 00:55:00.144 ERROR (MainThread) [homeassistant.components.automation.backup_create_backup] While executing automation automation.backup_create_backup
homeassistant  | Traceback (most recent call last):
homeassistant  |   File "/usr/src/homeassistant/homeassistant/components/automation/__init__.py", line 669, in async_trigger
homeassistant  |     await self.action_script.async_run(
homeassistant  |   File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1587, in async_run
homeassistant  |     return await asyncio.shield(run.async_run())
homeassistant  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 426, in async_run
homeassistant  |     await self._async_step(log_exceptions=False)
homeassistant  |   File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 479, in _async_step
homeassistant  |     self._handle_exception(
homeassistant  |   File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 502, in _handle_exception
homeassistant  |     raise exception
homeassistant  |   File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 476, in _async_step
homeassistant  |     await getattr(self, handler)()
homeassistant  |   File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 713, in _async_call_service_step
homeassistant  |     response_data = await self._async_run_long_action(
homeassistant  |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 675, in _async_run_long_action
homeassistant  |     return long_task.result()
homeassistant  |            ^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/src/homeassistant/homeassistant/core.py", line 2149, in async_call
homeassistant  |     response_data = await coro
homeassistant  |                     ^^^^^^^^^^
homeassistant  |   File "/usr/src/homeassistant/homeassistant/core.py", line 2186, in _execute_service
homeassistant  |     return await target(service_call)
homeassistant  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/src/homeassistant/homeassistant/components/backup/__init__.py", line 29, in async_handle_create_service
homeassistant  |     await backup_manager.generate_backup()
homeassistant  |   File "/usr/src/homeassistant/homeassistant/components/backup/manager.py", line 176, in generate_backup
homeassistant  |     raise result
homeassistant  |   File "/usr/src/homeassistant/homeassistant/components/zha/backup.py", line 15, in async_pre_backup
homeassistant  |     zha_gateway = get_zha_gateway(hass)
homeassistant  |                   ^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/src/homeassistant/homeassistant/components/zha/core/helpers.py", line 459, in get_zha_gateway
homeassistant  |     raise ValueError("No gateway object exists")
homeassistant  | ValueError: No gateway object exists

One more strategy:

I am using git as backup. It is a bit fiddly with the permissions, but I have a script which can be run as root.I have it run by a cron job a few times a day:

#!/bin/bash
cd <path to installation>
chmod -R a+r .
sudo -i -u <username> bash << EOF
cd <path to installation>
git add .
git commit -m "[BACKUP `date +'%Y-%m-%d %T'`]"
git push
EOF

Git makes it really easy to track changes or to revert only some part of the configuration. There are also great free online services to host your repository :slight_smile:

I am also using MariaDB and I have another machine replicate it continuously. Then on that other machine I make a backup every night with something like:

mysqldump -u <username> -p ha | lbzip2 -9czq > backup.bz2