Backup and Recovery
This document explains the backup and recovery strategy for Vaultwarden data stored in Azure Database for PostgreSQL Flexible Server.
Overview
Azure Database for PostgreSQL Flexible Server provides built-in automated backups with no additional configuration required. Backups are automatically enabled when the PostgreSQL server is provisioned.
Backup Features
- Continuous automated backups: Full snapshots plus transaction-log archival
- Point-in-time restore (PITR): Restore to any second within the retention period
- 35-day retention: Default backup retention period (the maximum offered by the service)
- Geo-redundant backup: Enabled by default — backups are replicated to the Azure paired region for cross-region disaster recovery
- No manual setup required: Backups are managed entirely by Azure
Backup Configuration
The PostgreSQL Flexible Server is deployed with the following backup settings:
| Setting | Value |
|---|---|
| Backup retention | 35 days |
| Backup type | Automated snapshots + continuous transaction-log archival |
| Point-in-time restore | Supported (any second within the retention period) |
| Geo-redundancy | Enabled (replicated to the Azure paired region) |
Note: Geo-redundant backup is set at server creation time and cannot be toggled on an existing PostgreSQL Flexible Server — changing it requires recreating the server (and migrating data).
Recovery Procedures
Point-in-Time Restore
Restore the database to any point within the retention period:
# Restore to a specific point in time
az postgres flexible-server restore \
--resource-group vaultwarden-dev-rg \
--name vaultwarden-dev-psql-restored \
--source-server vaultwarden-dev-psql \
--restore-time "2024-01-15T10:30:00Z"
Note: This creates a new server with the restored data. You will need to update the DATABASE_URL secret in Key Vault to point to the new server.
Manual Backup with pg_dump
For additional backup control, use pg_dump:
# Set variables
RESOURCE_GROUP="vaultwarden-dev-rg"
SERVER_NAME="vaultwarden-dev-psql"
DB_NAME="vaultwarden"
ADMIN_USER="vaultwardenadmin"
# Get the server FQDN
FQDN=$(az postgres flexible-server show \
--resource-group "$RESOURCE_GROUP" \
--name "$SERVER_NAME" \
--query "fullyQualifiedDomainName" -o tsv)
# Set password via environment variable (avoid passing in connection string)
export PGPASSWORD="<your-admin-password>"
# Create a backup (requires network access to the server)
pg_dump "postgresql://${ADMIN_USER}@${FQDN}:5432/${DB_NAME}?sslmode=require" \
--file vaultwarden-backup.sql
unset PGPASSWORD
Note: Since the PostgreSQL server is VNet-integrated (private access only), pg_dump must be run from a machine with network access to the VNet (e.g., an Azure VM in the same VNet, or via VPN/ExpressRoute).
Restore from pg_dump
export PGPASSWORD="<your-admin-password>"
# Restore from a backup file
psql "postgresql://${ADMIN_USER}@${FQDN}:5432/${DB_NAME}?sslmode=require" \
--file vaultwarden-backup.sql
unset PGPASSWORD
Verifying Backups
Check Backup Status
az postgres flexible-server show \
--resource-group vaultwarden-dev-rg \
--name vaultwarden-dev-psql \
--query "{backupRetentionDays:backup.backupRetentionDays, geoRedundantBackup:backup.geoRedundantBackup, earliestRestoreDate:backup.earliestRestoreDate}"
Data Protection
In addition to automated backups, the deployment includes:
- Geo-redundant storage (GRS) for the Azure Files data share — attachments and Send files are replicated to the Azure paired region, providing disaster-recovery protection
- Optional CanNotDelete resource lock on the PostgreSQL server to prevent accidental deletion (enable by setting
enablePostgresqlLock=true; requiresMicrosoft.Authorization/locks/writepermission on the deploying principal) - VNet integration ensures the database is only accessible within the private network
- SSL enforcement for all database connections
- Encryption at rest managed by Azure
Troubleshooting
Cannot Restore to a Specific Point in Time
Cause: The requested restore time is outside the backup retention window.
Solution: Check the earliest available restore point:
az postgres flexible-server show \
--resource-group vaultwarden-dev-rg \
--name vaultwarden-dev-psql \
--query "backup.earliestRestoreDate"
Restore Creates a New Server
Expected behavior: Point-in-time restore always creates a new server. After verifying the restored data:
- Update the
DATABASE_URLsecret in Key Vault with the new server’s connection string - Restart the App Service to pick up the new connection
- Delete the old server when no longer needed