Back Up Vaultwarden and Test the Restore (Script Included)
Your whole Vaultwarden vault is one data folder. Make a safe copy of the database with Vaultwarden's built-in backup command, copy the whole folder off the server every day, and restore it once to prove it works.
Everything Vaultwarden keeps lives in one folder: data inside the container, which is vw-data if you followed our Docker setup. Back up that folder and you can rebuild the whole server. Lose it with no backup and every account and every password on the server is gone.
The steps here follow Vaultwarden's own wiki page, Backing up your vault. In the video we tested them for real on a test server (Vaultwarden 1.37.5 in Docker): we made a backup, deleted the data folder, watched the sign-in fail, then restored the backup and signed back in with all four logins still there.
What in the data folder do I need to back up?
- Must keep:
db.sqlite3, the database (it holds almost everything: accounts, and every item in every vault), and theattachmentsfolder (files attached to items are not in the database). - Should keep: the
rsa_keyfiles, which sign people's logins (lose them and everyone just has to sign in again), andconfig.json, the settings you changed on the admin page. - Optional:
sends(files sent with Send, which are meant to be short-lived) andicon_cache(website icons, fetched again on their own).
config.json holds your admin token and any email password in plain text, so encrypt any copy that leaves your server.
Can I just copy the database file?
Not while Vaultwarden is running: it may be in the middle of writing, and the copy can be broken. Use a backup command made for a database in use. Since version 1.32.1 Vaultwarden has one built in:
docker exec vaultwarden /vaultwarden backup
Change vaultwarden to your container's name. It answers Backup to 'data/db_YYYYMMDD_HHMMSS.sqlite3' was successful. That copy is written inside the same data folder, on the same disk, so it does not protect you until the folder is copied somewhere else.
A daily backup script
Run this on the computer that runs Docker (the Vaultwarden image has no scheduler inside it). It needs root, because the files in vw-data belong to the container's root user. Change the two paths at the top.
#!/bin/sh
# vw-backup.sh: a safe copy of the database,
# then the whole folder, off the server
set -e
# the folder with compose.yaml and vw-data
VW=/opt/vaultwarden
# another disk, or a folder you sync off this machine
OUT=/mnt/backups/vaultwarden
mkdir -p "$OUT"
cd "$VW"
# drop the last run's copy, then make a fresh one
find vw-data -maxdepth 1 -name 'db_*.sqlite3' -delete
docker exec vaultwarden /vaultwarden backup
tar -czf "$OUT/vw-$(date +%Y%m%d-%H%M).tar.gz" \
-C vw-data \
--exclude=db.sqlite3 \
--exclude=db.sqlite3-wal \
--exclude=db.sqlite3-shm \
--exclude=tmp .
Schedule it once a day with cron (sudo crontab -e):
30 3 * * * /opt/vaultwarden/vw-backup.sh
Then get the archives off the machine. The wiki suggests rclone for cloud storage, or restic, which also encrypts. If you copy plain archives to the cloud, encrypt them first (for example with age or gpg), because of config.json. Delete old archives now and then so the disk does not fill up.
How do I restore a Vaultwarden backup?
Stop Vaultwarden, put the files back, give the backup database the name db.sqlite3, and delete any old -wal file before starting again: an old write-ahead file next to a restored database can damage it. Keep your current data aside in case the backup is bad.
cd /opt/vaultwarden
docker compose stop vaultwarden
mv vw-data vw-data.before-restore
mkdir vw-data
tar -xzf /mnt/backups/vaultwarden/vw-YYYYMMDD-HHMM.tar.gz -C vw-data
mv vw-data/db_*.sqlite3 vw-data/db.sqlite3
rm -f vw-data/db.sqlite3-wal vw-data/db.sqlite3-shm
docker compose start vaultwarden
Sign in with your usual master password. Your vault should be exactly as it was when the backup ran.
How do I know my backup works?
Restore it. The wiki recommends running through a restore now and then. The safest rehearsal is on another machine or a spare folder, so your live server is never at risk: copy an archive there, follow the restore steps, start Vaultwarden, and sign in.
What this does not cover
- MySQL or PostgreSQL setups: the folder still needs copying, but the database is backed up with that database's own dump tool.
- The web vault's own Export vault: it saves one person's items, not the server. It is a good extra copy for yourself, but it does not replace a server backup.