What backup strategy when running Home Assistant in Docker?

So the way I backup seems overly involved, but it works.

1- Use Portainer to stop the Home Assistant container - if Home Assitant is running I’ve found files skip and don’t copy over

2- Sudo nautilus which pulls up the root file explorer and gets around the permission issues.

3- Copy the entire config directory to my NAS drive and backup folder

4- Start the container again in portainer after copying is complete

I mean, this works, but I really would like to automate the process if possible. I just haven’t figured out a good way to do that though.

Update - I think I figured out a way to automate. I wrote a script to backup and run it nightly through the crontab. Generally following the directions here - Using rsync and cron to automate incremental backups

First I created a script file called hass_backup.sh that stops the container, does the backup using rsync, then starts the home assistant docker container back up

docker stop homeassistant
rsync -ab --backup-dir=old_`date +%F` --delete --exclude=old_* /home/mwav3/homeassistant /media/mwav3/MyPassport/backups/hassrsync
docker start homeassistant

To make sure that all the root files copy, I did this in the global crontab by running sudo gedit /etc/crontab

I then added commands to run the script nightly at 2 AM as root. I also then added another command to the crontab to start the container at 2:15 AM in case anything happens where the first script fails at some point so Home Assistant doesn’t stay offline.

0 2    * * *    root    sh /home/mwav3/hass_backup.sh
15 2   * * *    mwav3     docker start homeassistant

Seems to be working. I’m sure there’s lots of other ways to do this.

8 Likes