Back up HashiCorp Vault to your homelab, without a cloud bill
A free, tested backup for a small Vault: a pull-based nightly copy over Tailscale with a locked-down SSH key, a restore drill, and an alert for when Vault seals itself after a reboot.
Why bother
My Vault had been running for months with no backup at all. One bad disk and every secret behind my deploys would be gone. The textbook answer is S3 snapshots and KMS auto-unseal, but for a one-person setup holding 600 KB of data, a cloud bill felt wrong. The homelab was already there.
The data is already encrypted
Vault encrypts everything it writes to storage. A copy of its data directory is useless without the unseal keys, so you can store that copy on ordinary disks without adding encryption on top. Keep the unseal keys somewhere else entirely, never next to the backup.
Pull, don’t push
If the Vault server pushes backups to the homelab, it needs write access there, and a compromised server could delete them. Turn it around: the homelab pulls. The server holds no credentials for the backup machine at all.
1. A key that can only do one thing
Generate a dedicated key on the homelab. On the Vault server, add it to authorized_keys with a forced command, a source-IP restriction and restrict, which also disables shells, port forwarding and agent forwarding:
from="<homelab-tailscale-ip>",restrict,command="docker run --rm --network none -v /srv/vault_data:/d:ro alpine:3.24 tar czf - -C /d ." ssh-ed25519 AAAA... homelab-vault-backupWhatever the client asks to run, the server runs only that command: a read-only, network-less container that streams a tarball. Using Docker also solves permissions, because the data is owned by Vault’s user and the container can read it without sudo.
2. A backup script that refuses bad backups
#!/usr/bin/env bash
set -euo pipefail
DEST="$HOME/backups/vault"; OUT="$DEST/vault-$(date +%F_%H%M).tgz"; TMP="$OUT.partial"
trap 'rm -f "$TMP"' EXIT
ssh -T -o BatchMode=yes -i ~/.ssh/vault_backup user@<vault-tailscale-ip> > "$TMP"
if gzip -t "$TMP" && tar tzf "$TMP" | grep -c '^\./core/' >/dev/null; then
mv "$TMP" "$OUT"
find "$DEST" -name 'vault-*.tgz' -mtime +30 -delete
else
echo "$(date -Is) FAILED" >> "$DEST/backup.log"; exit 1
fiTwo details matter. The archive is written to a temporary file and only renamed once it passes validation, so a failed night never replaces a good backup.
And note grep -c rather than grep -q. My first version used grep -q, which exits on the first match and kills tar mid-listing; with pipefail set, that reports the whole pipeline as failed. The check rejected a perfectly good backup.
Schedule it nightly:
30 3 * * * $HOME/bin/vault-backup.sh >/dev/null 2>&13. Prove you can restore
A backup you haven’t restored is a hope. Unpack the newest archive and start a throwaway Vault on it:
R=$(mktemp -d); tar xzf "$(ls -t ~/backups/vault/*.tgz | head -1)" -C "$R"
docker run -d --name vault-restore-test -v "$R":/vault/file \
-e 'VAULT_LOCAL_CONFIG={"storage":{"file":{"path":"/vault/file"}},"listener":[{"tcp":{"address":"127.0.0.1:8200","tls_disable":1}}],"disable_mlock":true}' \
hashicorp/vault:1.21.4 server
docker exec vault-restore-test sh -c 'VAULT_ADDR=http://127.0.0.1:8200 vault status'You want Initialized: true and the same key shares and threshold as production. Two traps: give Vault more than a few seconds to start before you query it, and clean up through Docker afterwards, because Vault’s entrypoint changes the owner of the extracted files.
4. Know when Vault seals itself
Without auto-unseal, every reboot seals Vault, and you usually find out when a deploy fails. /v1/sys/health returns 200 when unsealed and 503 when sealed, so a plain HTTP check is enough. I pointed Uptime Kuma on the homelab at it, with a 60-second interval and a notification to my phone.
Cost
- Storage: about 50 KB a night on disks I already own.
- Bandwidth: negligible, over Tailscale.
- Money: zero.