Database Backup & Recovery
Shielda's PostgreSQL database is hosted on AWS RDS with automated backups, encryption at rest, and optional cross-region replication for disaster recovery.
Overview
Shielda's PostgreSQL database is hosted on AWS RDS with automated backups, encryption at rest, and optional cross-region replication for disaster recovery.
Backup Configuration
Setting Value --------------------------- -------------------------------------- Engine PostgreSQL 16.4 Storage encryption AES-256 (AWS KMS) Multi-AZ Yes (production) Automated backup retention 14 days (configurable via dbbackupretention) Backup window 03:00–04:00 UTC daily Maintenance window Monday 04:30–05:30 UTC Deletion protection Enabled (production only) Final snapshot on delete Yes (production only) Performance Insights Enabled (7-day retention) Enhanced Monitoring 60-second interval CloudWatch logs postgresql, upgrade
Cross-Region Backup Replication
For production environments, automated backups can be replicated to a secondary AWS region for disaster recovery:
When enabled, the awsdbinstanceautomatedbackupsreplication resource copies each automated backup to the secondary region with the same retention period.
CloudWatch Backup Monitoring
A CloudWatch alarm ({prefix}-rds-backup-age) fires if the most recent backup is older than 26 hours, indicating a missed backup window. The alarm sends notifications to the configured SNS topic:
Recovery Procedures
Point-in-Time Recovery (PITR)
RDS supports PITR to any second within the retention window:
Snapshot Restore
Restore from snapshot aws rds restore-db-instance-from-db-snapshot \ --db-instance-identifier shielda-recovery-$(date +%Y%m%d) \ --db-snapshot-identifier rds:shielda-prod-postgres-2025-01-15-03-00
Cross-Region Recovery
If the primary region is unavailable:
Switch to the DR region Restore from the replicated backup Update DNS / connection strings to point to the new instance Verify application connectivity and data integrity
Terraform Resources
Resource File Purpose -------- ---- ------- awsdbinstance.main infra/control-plane/rds.tf Primary RDS instance awsdbparametergroup.pg16 infra/control-plane/rds.tf PostgreSQL parameters awsdbinstanceautomatedbackupsreplication.crossregion infra/control-plane/rds.tf Cross-region backup copy awscloudwatchmetricalarm.backupage infra/control-plane/rds.tf Missed backup alert awsiamrole.rdsmonitoring infra/control-plane/rds.tf Enhanced Monitoring role
Variables
Variable Default Description -------- ------- ----------- dbbackupretention 14 Backup retention in days dbbackupdrregion "" DR region (empty = disabled) dbbackupdrkmskeyarn "" KMS key for DR region encryption alarmsnstopicarn "" SNS topic for alarms dbmultiaz true Multi-AZ deployment