Overview
Regular database backups are critical for protecting patient data, appointment records, and user information in NutriFit. This guide covers manual and automated backup strategies for both SQLite (development) and MySQL (production).Database Configurations
NutriFit supports two database systems:| Environment | Database | Location | Configuration |
|---|---|---|---|
| Development | SQLite | database/database.sqlite | DB_CONNECTION=sqlite |
| Production | MySQL 8.0+ | Remote server | DB_CONNECTION=mysql |
SQLite Backups (Development)
Manual Backup
SQLite databases are single files, making backups straightforward:Automated Backup Script
Create a backup script atscripts/backup-sqlite.sh:
Restore SQLite Backup
MySQL Backups (Production)
Manual Backup with mysqldump
Full Database Backup
Compressed Backup
Backup Specific Tables
Backup with Structure Only (No Data)
Automated MySQL Backup Script
Createscripts/backup-mysql.sh:
Schedule Automated Backups
Using Cron (Recommended)
Add to server crontab:Using Laravel Scheduler
Create a backup command:app/Console/Commands/DatabaseBackup.php:
routes/console.php:
Restore MySQL Backup
From Uncompressed Backup
From Compressed Backup
Remote Backup Storage
Using rsync (Server-to-Server)
Sync backups to remote server:Using AWS S3
Install AWS CLI:Using Laravel Cloud Storage
Configure S3 inconfig/filesystems.php, then:
Backup Verification
Test Backup Integrity
SQLite
MySQL
Automated Verification Script
Backup Retention Policy
Recommended Strategy
| Frequency | Retention | Purpose |
|---|---|---|
| Daily | 7 days | Recent recovery points |
| Weekly | 4 weeks | Short-term history |
| Monthly | 12 months | Long-term archives |
| Yearly | Indefinite | Compliance/legal |
Implement Retention in Script
Monitoring and Alerts
Email Notifications
Add to backup script:Slack Notifications
Security Best Practices
Encrypt Backups
Encrypt Backups
Encrypt sensitive patient data in backups:
Secure Credentials
Secure Credentials
Never hardcode passwords. Use MySQL configuration file:Create Set permissions:
~/.my.cnf:Restrict Backup Access
Restrict Backup Access
Limit who can access backups:
Test Restores Regularly
Test Restores Regularly
Perform quarterly restore tests to verify backup integrity and team readiness.
Disaster Recovery Plan
Recovery Time Objective (RTO)
Target: Restore service within 2 hours of failure.Recovery Steps
-
Assess the situation
- Identify failure type (corruption, deletion, hardware failure)
- Determine last known good state
-
Prepare environment
-
Restore database
-
Verify integrity
-
Clear caches
-
Bring online
-
Monitor
- Check error logs
- Verify critical functions
- Monitor user reports
Related Documentation
Artisan Commands
Database migration and management commands
Scheduled Tasks
Automate backup tasks with scheduler