HA - Docker Backup (where are my devices, etc)

Hello, I am a software developer but am new to HA, after getting good with Hubitat, I decided to move over to running HA (Docker) on a RPi. When I installed the Docker image, I pointed to a minimal config file as it was a new build and was not aware of what to use as a base config.

Now that I have had some time to understand the system, I am trying to do a nightly rsync to a samba share on another computer but when I pull the files, I don’t see anything related to rebuilding the HA instance from a backup.

Here are the files listed in the docker container, but there is nothing that states my current devices, plugins, integrations, dashboards, etc? Where would that data be located so I can build from a backup set?

rsync -a --recursive --progress --verbose /var/lib/docker/containers/57e62cd764b0dfb1e269b666739c610db9a2055d6747508bdbd6db5ebccf85bd/ /mnt/fileshare/

image

config.v2.json looks like it has some information but nothing about my current devices, etc?
I was assuming that I could do a backup and rebuild the HA docker instance from backup files?

You should have bind mounted a folder “/config” for HA docker container to utilize.
That is where HA config files reside. Inside that folder “/config/.storage” that has ui configured items, entities and other important items

You should sync all of /config and make sure you also getting .storage

Thanks @tmjpugh, so I guess there would be a default location inside docker for that if you don’t provide one. I’ll try to look for that inside the container and add it to sync.

If you don’t define it, docker makes it and places it in /var/lib/docker/volumes I think

1 Like

Thanks again, I’ll look into that… i see a directory that matches up with the config here:

 "MountPoints": {
    "/home/pi/homeassistant/configuration.yaml": {
      "Source": "",
      "Destination": "/home/pi/homeassistant/configuration.yaml",
      "RW": true,
      "Name": "7cc00caa49c2407f878a7335db2e79084a0c31b1cee4360e696ce6a7e0e33202",
      "Driver": "local",
      "Type": "volume",
      "ID": "7b17c827f70203b1aec6423d85391ceb551c3f8565fbc561299fc3f52752e69e",
      "Spec": {},
      "SkipMountpointCreation": false
    }
  },

When I try to list that directory, there is a _data folder but nothing inside of it…

I’ll look at the documentation you mentioned and see if it says anything.

root@rpi-ha1:/var/lib/docker/volumes/7cc00caa49c2407f878a7335db2e79084a0c31b1cee4360e696ce6a7e0e33202/_data# ls -l
total 0

When you find configuration.yaml then you got the correct folder

You may be able to use Find

When I first installed the HA docker, I used this…

docker run -d \
  --name homeassistant \
  --privileged \
  --restart=unless-stopped \
  -e TZ=America/New_York \
  -v /home/pi/homeassistant/configuration.yaml \
  --network=host \
  ghcr.io/home-assistant/home-assistant:stable

I’m assuming that it would use that as the default container root but nothing else ever was populated there. Maybe I have permissions wrong, I am not a Unix admin by trade so it could be user error…

I found this using “find”:

find / -iname configuration.yaml
/var/lib/docker/overlay2/16f9ee054b248c68a0891998c56afceb562929a7b9ca061718f1ded690f6af0f/diff/config/configuration.yaml
/var/lib/docker/overlay2/16f9ee054b248c68a0891998c56afceb562929a7b9ca061718f1ded690f6af0f/diff/home/pi/homeassistant/configuration.yaml
/var/lib/docker/overlay2/16f9ee054b248c68a0891998c56afceb562929a7b9ca061718f1ded690f6af0f/merged/home/pi/homeassistant/configuration.yaml
/var/lib/docker/overlay2/16f9ee054b248c68a0891998c56afceb562929a7b9ca061718f1ded690f6af0f/merged/config/configuration.yaml

I’m probably trying to do backups from the wrong folder.

Found what appears to be the base install with databases, etc… i’ll copy that out and try to do a fresh install… thanks again for your help.

You should be mapping a volume with your docker run command to a persistent data folder on the host/pi for the config. Otherwise, every time you rebuild the container (which will be required when an new home assistant update comes out) your config files will not persist and will be deleted with each new container build.

Here’s how volumes and persisting data works with docker:

Docker containers by their nature are meant to be “Ethereal”, and volumes should be used to persist data, NOT finding the data within the container itself.

You should define a volume per the install documentation

Your run command should look like this instead

docker run -d \
  --name homeassistant \
  --privileged \
  --restart=unless-stopped \
  -e TZ=America/New_York \
  -v /home/pi/homeassistant/config:/config \
  --network=host \
  ghcr.io/home-assistant/home-assistant:stable

Once you do that all the config data will be located in your /home/pi/homeassistant/config directory.

From there, just backup that directory. I wrote this up about using rsync to do a backup of the config volume for home assistant container

1 Like

You mapped one file, not the config folder, and didn’t map that to anywhere that HA cares about. That means that most of your HA config is inside the container and will be lost.

Hopefully you’ve not done anything you care about losing.

1 Like

Thanks @mwav3 and @Tinkerer … I originally followed your thread that you posted here to use rsync. So what I finally did to pull the docker managed volume was to export it as tar:

sudo docker stop homeassistant
docker export home-assistant > /tmp/homeassistant.tar

So I’m guessing I can point to these files and rebuild the existing “mis-configured” install using the new docker run args you provided?

I’ll try this method once I get time later today.
Thanks again for your help.
Chuck

Yea I have a Zigbee and Zwave dongle running on the build that is mapped to the managed volume. Probably about 30+ devices currently, gonna try and map up the snapshot and see if it will open the existing databases, config files.

If you extract and put those config files on the host pi in the /home/pi/homeassistant/config directory then use the run command above it should create a new container and use those config files to restore your previous settings.

Before removing the old container, I’d stop it and make a new container with a different name, like homeassistantnew or homeassistant2. If that works, you can delete the old container and reuse the homeassistant name.

docker run -d \
  --name homeassistantnew \
  --privileged \
  --restart=unless-stopped \
  -e TZ=America/New_York \
  -v /home/pi/homeassistant/config:/config \
  --network=host \
  ghcr.io/home-assistant/home-assistant:stable

HA docker in your case already decided to put on config since that is the entire setup. If you are running HA Supervised it will install on /usr/share/hassio