Docker volumes hold the data that matters: databases, uploaded files, configuration, and everything your containers rebuild from. Lose a volume and you lose the application, even if the container images are safe. Learning how to back up Docker volumes to Backblaze B2 with Restic gives you offsite, encrypted, deduplicated backups for a few cents per gigabyte, with a restore process you can test before you ever need it.
Restic is a good fit for this job because it was built around the exact problems Docker users run into. It encrypts everything before upload, deduplicates unchanged data so nightly snapshots stay small, and stores snapshots in a repository you can open from any machine with the password. Backblaze B2 supplies the storage: S3-compatible object storage with no minimum fees, where you only pay for what you store and download.
What You Need Before You Start
You need a VPS or server running Docker, a Backblaze B2 account with a bucket, and Restic installed on the host. Install Restic from your distribution package manager or the official release binary. Create the B2 bucket as private, and note the bucket name and the endpoint for your region. Backblaze publishes one S3 endpoint per region, for example s3.us-west-000.backblazeb2.com for the US West region, so use the endpoint that matches where your bucket lives.
Next, create an application key in the B2 dashboard, restricted to the backup bucket. Restic talks to B2 through the S3-compatible API, so it uses the application key ID as the access key and the application key itself as the secret. Keep both in a credentials file the backup script reads, not in shell history. You also need a strong repository password, stored in a file readable only by root. Restic encrypts the repository with it and there is no password reset.
How to Back Up Docker Volumes to Backblaze B2 Step by Step
Start by initializing the repository. Set the repository location and credentials as environment variables, then run restic init:
export RESTIC_REPOSITORY="s3:https://s3.us-west-000.backblazeb2.com/my-docker-backups"
export AWS_ACCESS_KEY_ID="your-application-key-id"
export AWS_SECRET_ACCESS_KEY="your-application-key"
export RESTIC_PASSWORD_FILE="/root/.restic-password"
restic init
Once the repository exists, the simplest backup targets the Docker volumes directory directly. On a standard Docker host, named volumes live under /var/lib/docker/volumes. A first backup looks like this:
restic backup /var/lib/docker/volumes --tag docker-volumes
That works, but it has a real weakness. If a database container is writing while Restic reads its files, the snapshot can capture a half-written state. For static files this rarely matters, but for databases, stop the container first or dump the database to a file and back that up instead. A short stop is safer than a corrupt restore.
Backing Up Running Containers Without Corrupt Data
A practical pattern is a small shell script that stops the database container, runs the backup, and starts the container again. The downtime is usually seconds for small databases. For a WordPress stack with MySQL, the sequence is docker stop wordpress-db, then the Restic backup, then docker start wordpress-db. If even a few seconds of downtime is too much, use mysqldump or pg_dump inside the container, write the dump to a volume, and back up the dump file while the database keeps running.
If you already run scheduled volume backups with a different tool, the same stop-first rule applies, and the reasoning carries over. Our guide to backing up Docker volumes automatically covers the scheduling side in more depth, including how to pick which volumes are worth backing up nightly and which can wait for a weekly run.
Setting Up the Restic Repository on B2
Restic needs a few details to talk to B2 reliably. A backblaze b2 restic repository stores each snapshot as encrypted objects, so nothing readable ever leaves your server. Save the environment variables in a file such as /root/restic-env.sh and source it in your backup script. Set RESTIC_REPOSITORY to the S3 URL with your bucket name, and add the B2 endpoint explicitly if your Restic version does not pick it up from the URL. Check the connection with restic snapshots after init; an empty list means the repository is reachable and ready. If the command fails, the usual causes are a wrong endpoint, an application key without access to the bucket, or a bucket name typo.
One setting worth adding early is a retention policy. Restic keeps every snapshot until you tell it otherwise, so a nightly backup grows forever without pruning. A policy like restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune keeps a week of daily snapshots, a month of weekly ones, and half a year of monthly ones. Run it weekly rather than nightly, since prune rewrites repository data and takes longer than a normal backup. The same repository layout works for a whole server, not just Docker volumes; our guide to backing up a VPS to S3-compatible storage with Restic shows how the same commands cover system files and configuration directories.
Automating the Backup with Cron
A backup that needs you to remember it will fail the week you are busiest. Put the script in cron. A nightly run at 2 a.m. looks like this:
0 2 * * * /root/bin/backup-docker-volumes.sh >> /var/log/restic-backup.log 2>&1
A restic backup docker volumes script should source the environment file, stop the database containers, run restic backup, restart the containers, and log the output. Log files alone are not enough, because nobody reads them until something breaks. Pipe the log to your monitoring or mail setup, or at minimum check it weekly. A backup job that fails silently for a month is worse than no backup at all, because it gives you confidence you have not earned.
Test the cron job the first night by running the script by hand and confirming a new snapshot appears with restic snapshots. After that, a weekly restic check confirms the repository is still readable. That schedule, the logging, and the regular verification are what make docker volume backup automation work in practice, not just the backup command itself.
Restoring a Volume from B2
Backups only prove their worth at restore time, so test one before you trust the setup. List snapshots, pick the one you want, and restore it to a temporary directory:
restic snapshots
restic restore latest --target /tmp/restore-test
Inspect the restored files, then delete the test directory. To restore for real, stop the container that owns the volume, copy the files back into the volume directory, and start the container. Restic restores files with their original permissions, but check ownership with ls -la before starting the container again.
If you only need one file, restic restore accepts include patterns, so you can pull a single configuration file without restoring the whole volume. For full disaster recovery, install Restic on the new server, point it at the same B2 repository, and restore from the latest snapshot. The repository password is the only thing you cannot recover, so store it somewhere safe, separate from the server.
Costs, Limits, and What to Watch
Backblaze B2 charges for storage and downloads, with no charge for uploads, and the first 10 GB of storage is free. Restic deduplication keeps costs low because only changed blocks upload each night, and a typical small VPS with a few gigabytes of volume data usually costs well under a dollar a month. Prices change, so check official pricing before budgeting. The cost that catches people off guard is the download side: restoring a large snapshot counts as egress, so test restores on a small volume first if you are watching the bill.
Compare providers before committing if price is the deciding factor. Our comparison of S3, Backblaze B2, and Cloudflare R2 backup pricing breaks down storage, egress, and minimum charges side by side. B2 wins on simplicity and price for most small setups, but R2 can be cheaper if you restore often, and a Storage Box can be simpler if you prefer rsync over object storage. The Backblaze B2 vs Hetzner Storage Box vs Wasabi guide looks at the same choice from the angle of a single VPS owner rather than a large deployment.
There are limits to know about. Restic has no built-in scheduling, so cron carries that job. It has no graphical interface, so everything happens in the terminal. Backups slow down when a volume holds many small files, because each file needs metadata, and the first backup is always the slowest since nothing is deduplicated yet. Test the full cycle once, while you still have time to fix it. If you are weighing Restic against other tools, our Duplicati vs Restic vs Kopia comparison covers the trade-offs for Docker volumes specifically, including where a GUI matters and where Restic’s speed and encryption win.
Set the bucket up, initialize the repository, write the script, schedule it, and restore once to prove it works. After that, the backup runs on its own, and the only job left is checking the logs and the monthly prune.