WorkingTitle Database Backup System¶
Executive Summary¶
The WorkingTitle production database is protected by an enterprise-grade, automated backup system that ensures data safety and business continuity. The system creates validated backups every 6 hours, maintains optimal storage usage, and provides emergency restore capabilities.
Key Benefits:
- Zero Data Loss Risk: Automated backups with gold-standard validation
- Space Efficient: Intelligent compression and rotation (8MB → 8.5KB)
- Security First: No password exposure, industry-standard authentication
- Production Ready: Survives server reboots, handles failures gracefully
System Overview¶
Production Configuration¶
- Server:
195.24.67.210 - Database: PostgreSQL
workingtitle(8MB) - Schedule: Every 6 hours (00:00, 06:00, 12:00, 18:00)
- Retention: 2 recent backups + 1 emergency backup
- Monitoring: Real-time health checks with email alerts to
text@workingtitle.ru
Stems Backup Configuration¶
- Source:
/var/www/workingtitle/production/shared/stems - Schedule: Weekly (Mondays at 00:13)
- Retention: 30 days
- Compression: Gzip level 6
- Location:
/var/backups/workingtitle/stems/
Core Components¶
- Database Backup Script: Creates, validates, and rotates database backups
- Stems Backup Script: Compresses and backs up audio stems
- Systemd Services: Automated scheduling and execution
- Health Monitoring: Real-time system health checks
- Cleanup System: Automated log and backup maintenance
- Restore Tools: Emergency recovery capabilities
- Security Layer: Secure
.pgpassauthentication
Directory Structure¶
All server health system components are now centralized in the server_health_system/ directory:
server_health_system/
├── backup-config.conf # Centralized configuration
├── database-backup-production.sh # Database backup script
├── stems-backup-production.sh # Stems backup script
├── health-monitor-v2.sh # Health monitoring system
├── monitoring-cleanup.sh # Automated cleanup system
├── shared-functions.sh # Common functions
├── workingtitle-backup.service # Database backup systemd service
├── workingtitle-backup.timer # Database backup scheduler
├── workingtitle-stems-backup.service # Stems backup systemd service
├── workingtitle-stems-backup.timer # Stems backup scheduler
├── workingtitle-monitoring-cleanup.service # Cleanup systemd service
├── workingtitle-monitoring-cleanup.timer # Cleanup scheduler
└── setup-monitoring-v2.sh # Monitoring system setup
Quick Operations Reference¶
# Check system status
ssh root@195.24.67.210 '/var/www/workingtitle/production/scripts/database-backup-production.sh status'
# Manual backup
ssh root@195.24.67.210 'sudo -u postgres /var/www/workingtitle/production/scripts/database-backup-production.sh backup'
# Emergency restore
ssh root@195.24.67.210 '/var/www/workingtitle/production/scripts/database-restore-production.sh restore'
# View logs
ssh root@195.24.67.210 'tail -20 /var/log/workingtitle-backup.log'
# Check service status
ssh root@195.24.67.210 'systemctl status workingtitle-backup.timer'
Deployment¶
Prerequisites¶
- SSH access to production server:
root@195.24.67.210 - SSH key configured for passwordless access
- PostgreSQL running on production server
One-Command Deployment¶
./deploy-backup-system.sh deploy
What happens:
- Creates directories and sets permissions
- Deploys all backup system components
- Configures centralized settings (
/etc/workingtitle/backup.conf) - Sets up secure
.pgpassauthentication - Installs and enables systemd services
- Removes sensitive setup files for security
- Tests system functionality
Backup Strategy¶
Process & Validation¶
- Database Dump: PostgreSQL
pg_dumpwith maximum compression - Atomic Operations: Temporary files prevent corruption
- Gold-Standard Validation: Full restore test to temporary database
- Table Verification: Confirms all 11 tables restored successfully
- Smart Rotation: Keeps exactly 2 production + 1 emergency backup
Storage & Format¶
- Location:
/var/backups/workingtitle/production/ - Format: Compressed SQL dump (
gziplevel 9) - Naming:
workingtitle_production_YYYYMMDD_HHMMSS.sql.gz - Size: 8MB database → 8.5KB backup file
- Emergency: Weekly uncompressed backups for faster restore
Security Features¶
Authentication¶
- Method: PostgreSQL
.pgpassfiles (industry standard) - No Password Exposure: Zero passwords in process lists or scripts
- User Isolation: Service runs as
postgresuser (least privilege) - File Security:
.pgpassfiles secured with 600 permissions
Operational Security¶
- No Hardcoded Secrets: All credentials via
.pgpass - Sensitive File Cleanup: Setup scripts removed after deployment
- Audit Trail: Comprehensive logging of all operations
- Access Control: Strict file permissions and user isolation
Monitoring & Alerts¶
Automated Monitoring¶
- Backup Age: Alerts if no backup in 24+ hours
- Backup Integrity: Validates compression and restore capability
- Disk Space: Alerts if less than 1GB free space
- Service Health: Monitors systemd timer status
- Email Alerts: Sent to
text@workingtitle.ru
Health Check Commands¶
# Comprehensive system health
ssh root@195.24.67.210 '/var/www/workingtitle/production/scripts/backup-monitor.sh check'
# Detailed status report
ssh root@195.24.67.210 '/var/www/workingtitle/production/scripts/backup-monitor.sh status'
Emergency Procedures¶
Restore Process¶
# 1. SSH to production server
ssh root@195.24.67.210
# 2. Interactive restore (recommended)
/var/www/workingtitle/production/scripts/database-restore-production.sh restore
# 3. Or restore specific backup
/var/www/workingtitle/production/scripts/database-restore-production.sh restore /var/backups/workingtitle/production/backup_file.sql.gz
Restore Safety Features¶
- Pre-restore Backup: Creates emergency backup before any restore
- Service Management: Safely stops/starts application services
- Interactive Confirmation: Multiple confirmations for destructive operations
- Validation: Verifies restore success before completing
Troubleshooting¶
Service Issues¶
# Check and restart services
systemctl status workingtitle-backup.timer
systemctl restart workingtitle-backup.timer
systemctl daemon-reload
Authentication Issues¶
# Verify .pgpass file
ls -la /var/lib/postgresql/.pgpass
# Test database connection
sudo -u postgres psql -h localhost -U wtuser -d workingtitle -c "SELECT 1;"
Storage Issues¶
# Check usage
du -sh /var/backups/workingtitle/
# Manual cleanup if needed
find /var/backups/workingtitle -name "*.sql.gz" -mtime +7 -delete
Technical Details¶
File Locations¶
- Scripts:
/var/www/workingtitle/production/scripts/ - Backups:
/var/backups/workingtitle/production/ - Config:
/etc/workingtitle/backup.conf - Authentication:
/var/lib/postgresql/.pgpass - Logs:
/var/log/workingtitle-backup.log
Performance Metrics¶
- Backup Time: ~1 second for 8MB database
- Compression: 99.9% (8MB → 8.5KB)
- Validation: ~2 seconds for full restore test
- Storage: 24KB total for 2 production backups
System Requirements¶
- PostgreSQL 16+ with
pg_dump/pg_restore - Minimum 1GB free disk space
- 512MB memory limit per operation
- Local connections only (no external dependencies)
Status: ✅ ACTIVE AND OPERATIONAL
Last Updated: September 18, 2025
Version: 2.0 (Enterprise Security Edition)