Skip to content

Backup & Restore

Protect your data with regular backups.

Automated Backups

Cron Job

bash
# /etc/cron.d/ops-atlas-backup
0 2 * * * root /opt/ops-atlas/backup.sh

Backup Script

bash
#!/bin/bash
# backup.sh

DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_DIR=/backups/ops-atlas

# Create backup directory
mkdir -p $BACKUP_DIR

# Backup PostgreSQL
docker exec ops-atlas-db pg_dump -U postgres opsatlas | gzip > $BACKUP_DIR/db_$DATE.sql.gz

# Backup Redis
docker exec ops-atlas-redis redis-cli BGSAVE
docker cp ops-atlas-redis:/data/dump.rdb $BACKUP_DIR/redis_$DATE.rdb

# Cleanup old backups (keep 30 days)
find $BACKUP_DIR -type f -mtime +30 -delete

# Upload to S3 (optional)
aws s3 sync $BACKUP_DIR s3://your-bucket/ops-atlas-backups/

Manual Backup

bash
# Database
docker exec ops-atlas-db pg_dump -U postgres opsatlas > backup.sql

# Compress
gzip backup.sql

Restore

From SQL Backup

bash
# Stop application
docker-compose stop ops-atlas

# Restore database
gunzip -c backup.sql.gz | docker exec -i ops-atlas-db psql -U postgres opsatlas

# Start application
docker-compose start ops-atlas

Point-in-Time Recovery

For PostgreSQL with WAL archiving:

bash
# Restore to specific time
pg_restore --target-time="2025-01-15 10:30:00" ...

Disaster Recovery

Recovery Plan

  1. RTO (Recovery Time Objective): 1 hour
  2. RPO (Recovery Point Objective): 1 hour

Steps

  1. Provision new infrastructure
  2. Restore database from backup
  3. Update DNS
  4. Verify functionality
  5. Notify stakeholders

Testing Backups

Regularly test your backups:

bash
# Monthly backup test
./test-restore.sh --backup=latest --target=staging

Released under the MIT License.