Runbook — Vaultwarden backup & restore¶
Vaultwarden runs as a native systemd unit on pi-home (DietPi). Its data is a single SQLite database plus the web vault and icon cache.
- Unit:
vaultwarden.service(User=vaultwarden) - Data root:
/mnt/dietpi_userdata/vaultwarden(146 MB, the data root) db.sqlite3(+-wal,-shm) — the passwordsweb-vault/— static, can be re-copiedicon_cache/,tmp/,attachments/— replaceablevaultwarden.env(chmod 600),cert.pem,privkey.pem,rsa_key.pem— config + TLS keypair
Backup status. Vaultwarden is covered by the pi-home data branch: nightly restic of
/mnt/dietpi_userdatato BOTH/mnt/pi-hdd/ backups/pi-home/data(physical) andgdrive:backups/pi-home/data(off-site). The backup copies the SQLite files as they are — if the restore ever looks torn, fall back to the manual online backup (Option A) below, which is still the cleanest for a known-good single file.
Backup — manually, on demand¶
Because the DB is SQLite with a running process, do not just copy the file
mid-write — the -wal may not be checkpointed and the copy could be torn. Use
Vaultwarden's dump or stop the service.
Option A — SQLite online backup (recommended, no downtime)¶
Run an online VACUUM INTO to get a consistent snapshot (or the Bitwarden
sqlite3 backup):
# pi-home
sqlite3 /mnt/dietpi_userdata/vaultwarden/db.sqlite3 \
"VACUUM INTO '/var/tmp/vaultwarden-backup.sqlite3'"
# verify it opens + check count
sqlite3 /var/tmp/vaultwarden-backup.sqlite3 \
"SELECT count(*) FROM users; SELECT count(*) FROM ciphers;"
cp /mnt/dietpi_userdata/vaultwarden/vaultwarden.env /var/tmp/
Option B — stop, copy, start (most thorough)¶
sudo systemctl stop vaultwarden
sudo -u vaultwarden cp -a /mnt/dietpi_userdata/vaultwarden /var/tmp/vaultwarden-full
sudo systemctl start vaultwarden
Copy /var/tmp/vaultwarden* somewhere durable (a Drive remote, the pi-home
backup tree, or the restic repo) — /var/tmp is tmpfs and won't survive a
reboot.
Restore¶
- Stop Vaultwarden:
- Back up whatever is live first (in case you want to roll back):
- Restore the DB + env from the good snapshot, keeping ownership:
Remove stray
sudo -u vaultwarden cp <snapshot>/db.sqlite3 \ /mnt/dietpi_userdata/vaultwarden/db.sqlite3 sudo -u vaultwarden cp <snapshot>/vaultwarden.env \ /mnt/dietpi_userdata/vaultwarden/vaultwarden.env-wal/-shmfor the restored DB so SQLite re-inits cleanly: - Start and verify: Log in with a known-good credential; confirm a recent password/entry is present. Check the DB has your user count:
- Keep
db.sqlite3.pre-restoreuntil you're certain, then remove it.
Make this safe going forward¶
The pi-home timers back up /mnt/dietpi_userdata nightly to pi-hdd + gdrive.
The rest of this section is fallback tooling:
- Manual online backup (Option A) still useful before risky changes —
it produces one consistent
VACUUM INTOfile. - Restore path: pull the latest
pi-home/datasnapshot per the restic-restore runbook, then follow the Restore section here (stop →db.sqlite3.pre-restore→ restore DB + env → remove-wal/-shm→ start → verify counts). - Track open backup items in the GitHub Issues on this repo (the off-site leg depends on the gdrive OAuth client staying usable).