Back up Docker volumes automatically and you stop gambling with the one part of your stack that actually matters: the data. Containers are disposable by design. You can rebuild an image from a Dockerfile in minutes, but a deleted or corrupted volume takes your database, uploads, and config state with it. This guide walks through practical volume backup strategies that run on a schedule without you babysitting them: tar snapshots, restic and Kopia for deduplicated offsite copies, cron and systemd timers for automation, and restore drills that prove the backups actually work. It assumes you already have installed Docker and Compose on your VPS; everything else is plain shell.
Know What to Back Up
Not everything inside Docker deserves a backup. Named volumes and bind mounts hold persistent data. Images rebuild from Dockerfiles. Container filesystems are ephemeral: anything written outside a mounted volume vanishes when the container is replaced.
Start by listing what you actually store:
docker volume ls
docker inspect -f '{{ .Mounts }}' your_container_name
For a typical stack the answer is small: the database volume (Postgres, MySQL, or MariaDB), the uploads/media volume for apps like Nextcloud or Ghost, and any config volume you mount rather than template from compose files. Back up the data directories, not Docker’s internals. Pointing tar at /var/lib/docker copies the overlay filesystem, image layers, and live lockfiles. It is slow, bloated, and unreliable to restore. Backup per volume, with names that tell you what is inside.
Back Up Docker Volumes with tar Snapshots
The simplest reliable approach to back up Docker volumes is a tar snapshot taken through a temporary container. Never tar a volume’s files while its database is actively writing unless you are fine with a torn backup.
Single volume, one line:
docker run --rm --volumes-from mydb -v /backup:/backup ubuntu
tar czf /backup/mydb-$(date +%F).tar.gz /var/lib/mysql
Back up every volume on the host with a loop:
#!/bin/bash
# /usr/local/bin/docker-backup.sh
set -euo pipefail
OUT=/backup/docker
mkdir -p "$OUT"
DATE=$(date +%F)
for v in $(docker volume ls -q); do
docker run --rm
-v "$v":/vol:ro
-v "$OUT":/out
ubuntu tar czf "/out/$v-$DATE.tar.gz" -C /vol .
done
Mounting the source volume read-only (:ro) stops tar from tripping over files it cannot read and keeps the snapshot consistent with what was on disk when the command ran. For databases, the safer sequence is: stop the container or take a native dump first, then snapshot. A mysqldump or pg_dump piped to gzip, stored alongside the tar file, gives you a second restore path for pennies.
Use Restic or Kopia for Deduplicated Offsite Backups
Tar snapshots work until your backups get big. Daily full tarballs of a 40 GB volume mean 40 GB of new storage every day, and copying all of that offsite every night is wasteful. Deduplicating tools fix this: they store each block once and upload only changed chunks.
Restic is a good default for deduplicated, encrypted backups. A restic docker volume backup streams straight into an offsite repository, so you never stage big tarballs locally:
restic -r rclone:b2:docker-backups init
docker run --rm --volumes-from mydb ubuntu
tar -cf - /var/lib/mysql |
restic -r rclone:b2:docker-backups backup --stdin --stdin-filename mydb.tar
Restic encrypts everything client-side, so the storage provider never sees your data. Retention stays one command:
restic -r rclone:b2:docker-backups forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune
Kopia takes the same approach with a friendlier policy system if you prefer declarative snapshot policies over scripts. If you want a deeper head-to-head before committing, compare restic, Kopia, and Duplicati for Docker volumes first. And if you would rather pay for something that handles scheduling, agents, and support for you, there are paid backup tools built for Docker volumes worth a look.
Schedule It with Cron or systemd Timers
A backup script that runs manually is a backup that stops running the week you get busy. Pick one scheduler and commit to it.
Cron is the fastest route. Run the backup as root at 02:00 daily:
0 2 * * * /usr/local/bin/docker-backup.sh >> /var/log/docker-backup.log 2>&1
systemd timers are the better choice on modern Ubuntu: they handle missed runs after downtime, journal logging, and failure notifications without extra tooling. A minimal pair looks like this:
# /etc/systemd/system/docker-backup.service
[Unit]
Description=Back up Docker volumes
[Service]
Type=oneshot
ExecStart=/usr/local/bin/docker-backup.sh
# /etc/systemd/system/docker-backup.timer
[Unit]
Description=Daily Docker volume backup
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
Then:
systemctl enable --now docker-backup.timer
systemctl list-timers docker-backup.timer
Persistent=true means a server that was down at 02:00 still runs the backup when it comes back up. Cron never does that on its own. Either way, log to a file and check it weekly. A scheduler nobody watches is how six months of failed backups go unnoticed.
Copy Backups Offsite with rsync or rclone
A backup that lives on the same disk as the data is not a backup. Ship the files somewhere else the same night they are created.
Rsync to a second VPS or a home server over SSH:
rsync -az --delete /backup/docker/ [email protected]:/srv/docker-backups/
Or push straight to object storage with rclone:
rclone sync /backup/docker b2:docker-backups --fast-list --transfers 8
If you have not picked a destination yet, compare offsite storage options for self-hosting to match pricing and features to your volume size. One more rule: plain tarballs need encryption before they leave your network (gpg --symmetric is enough), while restic and Kopia encrypt by default, which is one more reason to prefer them for offsite copies.
Prove Restores Work Before You Need Them
An untested backup is a rumor. Test restores on a schedule, not during an outage.
Restore a tar snapshot into a scratch volume:
docker volume create test-restore
docker run --rm -v test-restore:/vol -v /backup/docker:/backup
ubuntu bash -c "cd /vol && tar xzf /backup/mydb-2026-10-24.tar.gz"
docker run --rm -v test-restore:/data ubuntu ls /data
For a database, go one step further: start the actual database container against the restored volume, connect, and run a query that proves the data is intact and recent. With restic the flow is identical in shape:
restic -r rclone:b2:docker-backups restore latest --target /tmp/restore-test
Run this drill quarterly and keep notes on what breaks. The drill documents your recovery steps; the steps are the product, not the backup files.
Mistakes That Silently Break Docker Backups
These are the failure modes I see most often, roughly in order of how quietly they strike:
Snapshotting a live database volume with no dump. Tar copies files as they change; a Postgres data dir mid-checkpoint can restore into a state the database refuses to open. Dump first, then snapshot.
Backing up /var/lib/docker as a whole. You get image layers, build cache, and lockfiles: gigabytes of restore-hostile noise. Back up named volumes individually.
No retention policy. A nightly 30 GB tarball fills a 200 GB disk in a week, and the backup that kills the server it was protecting is a special kind of failure. Prune with find /backup -name "*.tar.gz" -mtime +14 -delete or use restic’s forget policies.
Backups on the same disk only. A failed SSD takes the data and the backups together. Offsite or it did not happen.
Lost encryption keys. An encrypted backup you cannot decrypt is indistinguishable from no backup. Store the restic password and GPG passphrase in a password manager, and separately from the backups themselves.
Put it together and the system is small: a docker volume backup script, a timer, an offsite copy, a retention rule, and a quarterly restore drill. Once set up, automated docker backups remove the human from the loop, which is exactly why they keep working when manual ones stop. That is everything a self-hosted Docker stack needs to survive a lost volume.