Runbook: Restore a Database Backup
When to Use
- Data corruption or accidental deletion
- Rolling back to a known-good state
- Migrating data between servers
Prerequisites
- SSH access as the
deployuser - Backups exist in
/data/backups/postgres/
Steps
1. List available backups
Backups follow the naming pattern <database>_YYYYMMDD_HHMMSS.sql.gz. The backup cron runs daily at 02:00 UTC with 7-day retention.
2. Choose a backup
Identify the backup file to restore. Example:
3. Run the restore script
Interactive mode (prompts for confirmation):
The script will list available backups and prompt you to select one.
Non-interactive mode (for scripting):
4. Verify the restored data
Connect to the database and check key tables:
docker exec -i platform-postgres-1 psql -U postgres -d <database_name> -c "\dt"
docker exec -i platform-postgres-1 psql -U postgres -d <database_name> -c "SELECT count(*) FROM <table_name>;"
5. Restart the application
After restoring, restart the app to ensure it reconnects cleanly:
6. Verify the application
Important Notes
- Restoring drops the existing database and recreates it from the backup. All data written after the backup was taken will be lost.
- Backups are retained for 7 days. If you need a backup older than 7 days, you must have configured off-server backup sync (e.g., via
rclone). - The restore script operates on the platform PostgreSQL instance. It does not affect other databases on the same instance.
- Consider stopping the application before restoring to avoid write conflicts: