Chapter 23 / 28
Vault Snapshots: Backing Up the Vault
HashiCorp Vault For Beginners7 min read
HashiCorp Vault is your secrets hub—your source of cryptographic truth. Whether you're storing credentials, access tokens, encryption keys, or policies, it's all sitting in one secure place.
But here’s the reality: even secrets need backups.
If your Vault server crashes, hardware fails, or an OS patch goes sideways, you need a plan to recover the state of Vault.
That plan? Snapshots.
This chapter covers everything about Vault Snapshots:
- What they are
- How they work
- Where they apply
- How to back up and restore
- Secure practices and automation options
What Is a Vault Snapshot?
A snapshot is an export of Vault's Raft storage backend data—a binary archive of Vault’s entire state at a point in time.
Think of it like a photo of Vault’s memory and disk content:
- Enabled secrets engines
- Stored secrets
- Access policies
- Tokens and leases
- Audit configuration
- Identity data
- Internal cluster metadata
Only the Raft integrated storage backend supports snapshots. If you're using Consul or another backend, snapshotting must be handled separately on the backend itself.
Snapshot Internals
Under the hood, Vault's snapshot mechanism pauses writes temporarily, reads the entire Raft state, and saves it as a binary file. This is a point-in-time consistent backup—Vault ensures that no mid-write state is captured.
- Format: Binary
- Contains: All cluster nodes’ data (single or multi-node)
- Encrypted? No, it's raw state. You must secure it manually.
When Should You Take a Snapshot?
- Before major upgrades
- Before changing secrets engines or policies
- On a schedule (e.g., every 6–12 hours in production)
- Before rotating encryption keys
- As part of disaster recovery planning
Creating a Snapshot
Snapshots are created using the Vault CLI or API.
Pre-requisites:
- Vault must be unsealed
- You need
sudoor root access to write backup files - You must have
sudo_capabilities = ["snapshot"]in your Vault policy
Create a Snapshot via CLI
vault operator raft snapshot save /opt/vault/backups/vault-snapshot-$(date +%F-%H-%M).snap
You’ll see:
Saved snapshot to: /opt/vault/backups/vault-snapshot-2025-04-14-22-11.snap
Always use timestamped filenames to avoid overwriting.
Create Snapshot via API
curl \
--header "X-Vault-Token: $VAULT_TOKEN" \
--output vault-snapshot.snap \
https://<vault-address>/v1/sys/storage/raft/snapshot
This returns the snapshot file as a binary stream.
If you're doing this in a cron job or CI/CD pipeline, redirect the output to a file.
Secure the Snapshot
This part is critical.
Vault snapshots contain sensitive data. Anyone with read access can recover all secrets.
- Store snapshots in encrypted buckets (e.g., AWS S3 with server-side encryption)
- Encrypt locally using GPG or OpenSSL
- Lock down filesystem access (
chmod 600) - Don't commit or upload to shared systems
- Monitor and rotate backups periodically
Restoring a Snapshot
A snapshot can only be restored:
- When the Vault server is sealed
- And the Raft cluster is not running
This is a destructive operation. You’ll wipe the current Vault state and replace it with the snapshot.
Step-by-Step: Restore Process
1. Stop the Vault server:
sudo systemctl stop vault
2. Move or delete the current data directory:
sudo mv /opt/vault/data /opt/vault/data.bak.$(date +%F-%H-%M)
sudo mkdir -p /opt/vault/data
3. Restore the snapshot:
vault operator raft snapshot restore /opt/vault/backups/vault-snapshot-2025-04-14-22-11.snap
4. Restart the Vault server:
sudo systemctl start vault
5. Unseal Vault (if sealed):
vault operator unseal
You should now see all secrets, policies, and engines restored as per the snapshot.
Automating Snapshot Backups
Here’s a sample cron job that saves a Vault snapshot every hour:
0 * * * * vault operator raft snapshot save /opt/vault/backups/$(date +\%F-\%H-\%M).snap
You can also GPG-encrypt them:
vault operator raft snapshot save - > vault.snap && \
gpg --output vault.snap.gpg --encrypt --recipient backup@company.com vault.snap
Upload the encrypted file to S3:
aws s3 cp vault.snap.gpg s3://my-secure-vault-backups/
Snapshot Policies – Who Can Do What
Snapshots are powerful. Use fine-grained policy control:
path "sys/storage/raft/snapshot" {
capabilities = ["read"]
}
Use this only for trusted operators or CI/CD roles with vault-wide access.
Recap
Vault snapshots are your last line of defense when disaster strikes. In this chapter, you learned:
- What a snapshot is and how it works
- How to create snapshots via CLI and API
- How to restore a snapshot safely
- How to encrypt and automate backups
- Best practices for snapshot security and access control