Hello Self-Hosters,
What is the best practice for backing up data from docker as a self-hoster looking for ease of maintenance and foolproof backups? (pick only one :D )
Assume directories with user data are mapped to a NAS share via NFS and backups are handled separately.
My bigger concern here is how do you handle all the other stuff that is stored locally on the server, like caches, databases, etc. The backup target will eventually be the NAS and then from there it’ll be double-backed up to externals.
-
Is it better to run
cp /var/lib/docker/volumes/* /backupLocation
every once in a while, or is it preferable to define mountpoints for everything inside of/home/user/Containers
and then use a script to sync it to wherever you keep backups? What pros and cons have you seen or experienced with these approaches? -
How do you test your backups? I’m thinking about digging up an old PC to use to test backups. I assume I can just edit the ip addresses in the docker compose, mount my NFS dirs, and failover to see if it runs.
-
I started documenting my system in my notes and making a checklist for what I need to backup and where it’s stored. Currently trying to figure out if I want to move some directories for consistency. Can I just do
docker-compose down
edit the mountpoints indocker-compose.yml
and rundocker-compose up
to get a working system?
I just took line of least effort, all my docker containers are hosted on dedicated VM in proxmox, so I just backup entire VM on weekly basis to my NAS. Already had to restore it once when I was replacing SSD in proxmox host, worked like a charm.
While that’s an easy solution it makes it impossible or rather difficult to restore single containers and/or files.
I miss this from cloud hosting. It’s helpful to be able to save, clone, or do whatever with the current machine state and easily just flash back to where you were if you mess something up. Might be too much to set up for my current homelab though. My server does have btrfs snapshots of everything directly in grub which has let me roll back a few big screwups here and there.
caches are never really a concern to me they will regen after the fact, from your description i would worry more about db, this is dependent though in what you’re using and what you are storing. if the concern is having the same system intact then my primary concern would be backing up any config file you have. in cases of failure you mainly want to protect against data loss, if it takes time to regenerate cache/db that’s time well spent for simplicity of actively maintaining your system
I created my own script/tool using rsync to handle backups and transferring data.
My needs are quite smaller with just a computer and two Raspberry Pi’s but I found rsync to be really useful overall.
My backup strategy is to make a complete backup on the local device (Computer / RPi4 / RPi5) then copy all those backups to a Storage partition on my computer, then make a whole backup from the partition to an externally attached SSD.
The RPi’s both use docker/podman containers so I make sure any persistent data is in mounted directories. I usually stop all containers before performing a backup, especially things with databases.
Everything in the docker containers is either hit or miss when it comes to restoring. The simple docker images restore as it they were untouched and will launch like nothing happened. I have a PieFed instance that must be rebuilt after restoring a backup. Since PieFed’s persistent data is in mount points, everything works perfectly after a fresh build.
I can send a link to my rsync tool if that’s any interest to anyone. I’ve found it super useful for backups and minimizes so much headache for myself when it comes to transferring files between different network connected devices.
I use Borg to backup the default volume directory and my compose files. If you’re interested I can share my backup script.