Backup Automation & Disaster Recovery
Database backups run automatically every night to guarantee zero data loss in the event of catastrophic server hardware failure or accidental data deletion.
β° Nightly Automated Backups (backup_databases.sh)
Automated database backups are scheduled via the root userβs crontab:
# Runs daily at 02:00 AM UTC0 2 * * * /opt/vps-stack/scripts/backup_databases.sh > /dev/null 2>&1Script Workflow
The script /opt/vps-stack/scripts/backup_databases.sh:
- Creates the target directory
/opt/vps-stack/backupsif missing. - Extracts live PostgreSQL dumps via
docker exec -t supabase-db pg_dump -U postgres postgres. - Compresses the raw SQL dump stream using
gzip -9to minimize disk footprint:/opt/vps-stack/backups/planovi_db_backup_YYYY-MM-DD_HHMMSS.sql.gz - Enforces a 14-day retention policy by deleting archive files older than 14 days (
find ... -mtime +14 -delete). - Logs execution metrics and backup file sizes.
πΎ Manual Snapshot Execution
Before performing major database schema migrations or Edge Function refactorings, create an immediate manual snapshot:
# Execute immediate backupsudo /opt/vps-stack/scripts/backup_databases.sh
# Verify the newly created archivels -lh /opt/vps-stack/backups/π Disaster Recovery: Restoring a Database Backup
Follow this runbook to restore a PostgreSQL snapshot onto supabase-db:
Step 1: Identify Backup File
cd /opt/vps-stack/backupsls -lth *.sql.gz# Example: planovi_db_backup_2026-09-20_020001.sql.gzStep 2: Stop Dependent Containers
To prevent write conflicts and active connections during restoration:
cd /opt/vps-stackdocker stop supabase-postgrest supabase-auth supabase-edge-runtimeStep 3: Stream Restoration into PostgreSQL
gunzip -c /opt/vps-stack/backups/planovi_db_backup_2026-09-20_020001.sql.gz | \ docker exec -i supabase-db psql -U postgres -d postgresStep 4: Restart Stack & Verify Integrity
docker start supabase-postgrest supabase-auth supabase-edge-runtime
# Verify database connection and tablesdocker exec -it supabase-db psql -U postgres -d postgres -c "\dt"