Documentation Index
Fetch the complete documentation index at: https://mintlify.com/diegolozadev/DataMed/llms.txt
Use this file to discover all available pages before exploring further.
Backup & Restore
Protecting patient data is critical. This guide covers backup strategies, automation, and recovery procedures for DataMed’s database.Why Backups Matter
Data Loss Prevention
Hardware failures, software bugs, or human error can cause data loss. Backups provide recovery points.
Regulatory Compliance
Healthcare data regulations often require backup and retention policies.
Migration Safety
Backups let you test migrations and rollback if issues occur.
Disaster Recovery
Complete system failure requires recent backups to restore operations quickly.
PostgreSQL Backups (Production)
Manual Backup with pg_dump
Create a complete database backup:-h: Database host-U: Database user-d: Database name>: Redirect output to file
You’ll be prompted for the database password. Set
PGPASSWORD environment variable to automate.Backup with Compression
Save storage space with gzip:Custom Format Backup
Use PostgreSQL’s custom format for flexibility:- Faster compression
- Selective table restore
- Parallel restore support
Backup Specific Tables
Restoring PostgreSQL Backups
Restore from SQL File
Restore from Custom Format
-c: Clean (drop) database objects before restoring-j 4: Use 4 parallel jobs for faster restore
SQLite Backups (Development)
Copy Database File
Simplest method for SQLite:SQLite Dump
Create SQL text dump:Restore SQLite from SQL
Automated Backup Scripts
Daily Backup Script
Create/usr/local/bin/backup_datamed.sh:
backup_datamed.sh
Schedule with Cron
Run daily at 2:00 AM:Render-Specific Backups
Render provides automatic PostgreSQL backups, but you should also maintain your own.Manual Backup from Render
Automated Backup from Render
Use GitHub Actions to schedule backups:.github/workflows/backup.yml
Backup Storage Options
Local Storage
Pros: Fast, simple
Cons: Vulnerable to hardware failure
Use for: Development, short-term backups
Cons: Vulnerable to hardware failure
Use for: Development, short-term backups
AWS S3
Pros: Durable, versioned, encrypted
Cons: Cost scales with storage
Use for: Production, long-term retention
Cons: Cost scales with storage
Use for: Production, long-term retention
Google Cloud Storage
Pros: Similar to S3, good performance
Cons: Requires GCP account
Use for: Production, GCP infrastructure
Cons: Requires GCP account
Use for: Production, GCP infrastructure
Backblaze B2
Pros: Lower cost than S3
Cons: Slower retrieval
Use for: Cost-effective long-term storage
Cons: Slower retrieval
Use for: Cost-effective long-term storage
Backup Verification
Always verify backups can be restored:Test Restore Process
Monthly Verification Schedule
Django Data Export (Backup Alternative)
Export data using Django’s dumpdata:Export Specific Apps
Restore from Django JSON
Disaster Recovery Plan
Recovery Time Objective (RTO)
Target: < 4 hours from disaster to full operationRecovery Point Objective (RPO)
Target: < 24 hours of data loss (daily backups)Recovery Procedure
Provision New Infrastructure
If hardware failed:
- Deploy new Render service
- Create new PostgreSQL database
- Configure environment variables
Backup Checklist
Daily Tasks
Daily Tasks
- Automated backup runs successfully
- Backup file size reasonable (not 0 bytes)
- Backup stored off-server
Weekly Tasks
Weekly Tasks
- Review backup logs for errors
- Verify backup file integrity
- Check storage capacity
Monthly Tasks
Monthly Tasks
- Test restore procedure
- Review retention policy
- Audit backup access controls
- Update disaster recovery documentation
Quarterly Tasks
Quarterly Tasks
- Full disaster recovery drill
- Review and update backup scripts
- Evaluate backup storage costs
Security Considerations
Encryption at Rest
Access Control
- Restrict backup access to authorized personnel only
- Use IAM roles for cloud storage (AWS, GCP)
- Enable audit logging on backup storage
- Rotate encryption keys regularly
Next Steps
Database Schema
Understand what data you’re backing up
Migrations
Backup before schema changes
Deployment
Integrate backups into deployment process
Configuration
Configure database connection for backups