This repository was archived by the owner on Oct 10, 2025. It is now read-only.
Commit 022a931
committed
bb0ba2e feat: [#21] complete database backup automation implementation (Jose Celano)
372be70 refactor: [#21] implement single template approach for environment configuration (Jose Celano)
40a32a2 feat: [#21] implement SSL and backup configuration validation (Jose Celano)
8134c59 docs: [#21] add comprehensive application installation automation plan (Jose Celano)
a29e40b docs: [#21] add comprehensive application installation automation plan (Jose Celano)
Pull request description:
## Summary
This PR implements automated MySQL database backup functionality as part of Phase 3 of Issue #21 (Complete Application Installation Automation). This phase focuses on backup automation, laying the foundation for subsequent SSL automation work.
## 🎯 What's Implemented
### Core Backup Automation
- **MySQL Backup Script** (`application/share/bin/mysql-backup.sh`)
- Full database backup with compression (gzip)
- Configurable retention policy (default: 7 days)
- Comprehensive logging with timestamps
- Error handling and validation
- Non-interactive operation for automation
### Infrastructure Integration
- **Deployment Integration** in `infrastructure/scripts/deploy-app.sh`
- `setup_backup_automation()` function
- Automated cron job installation
- Environment-aware configuration
- Part of the standard deployment workflow
### Configuration Management
- **Environment Variables** added to configuration templates
- `ENABLE_DB_BACKUPS` (boolean) - Enable/disable backup automation
- `BACKUP_RETENTION_DAYS` (integer) - Number of days to retain backups
- **Default Settings** - Backups enabled by default in local development
- **Template Updates** - All environment templates include backup variables
### Documentation & Testing
- **Comprehensive Testing Guide** (`docs/guides/database-backup-testing-guide.md`)
- Manual testing procedures
- Validation steps for backup content
- Troubleshooting guidance
- **Updated Progress Documentation** - Issue #21 progress tracking updated
## 🧪 Testing Performed
### Automated Testing
- ✅ **CI Pipeline**: All linting and unit tests pass
- ✅ **Infrastructure Tests**: Terraform validation, cloud-init syntax
- ✅ **Application Tests**: Docker Compose validation, script syntax
### Manual Testing (Comprehensive)
- ✅ **End-to-End Deployment**: Full infrastructure + application deployment
- ✅ **Backup Script Execution**: Manual and automated backup creation
- ✅ **Backup Content Validation**: Schema inspection, data completeness
- ✅ **Cron Job Integration**: Automated backup scheduling and execution
- ✅ **Log File Validation**: Proper logging and error reporting
- ✅ **Retention Policy**: Old backup cleanup verification
### Backup Content Verification
```sql
-- Verified backup contains complete schema and data
SHOW TABLES; -- ✅ All tracker tables present
SELECT COUNT(*) FROM torrust_tracker_keys; -- ✅ Data preserved
-- Full restoration capability confirmed
```
## 🏗️ Twelve-Factor Architecture Compliance
This implementation maintains strict twelve-factor app principles:
- **Config**: Environment variables for all settings
- **Build/Release/Run**: Clear separation maintained
- **Backing Services**: MySQL treated as attached resource
- **Processes**: Stateless backup script design
- **Logs**: Structured logging to files and stdout
## 🔧 Configuration
### Enable Backup Automation
```bash
# In environment files (.env, local.env, production.env)
ENABLE_DB_BACKUPS=true
BACKUP_RETENTION_DAYS=7
```
### Backup Storage
- **Location**: `/home/torrust/backups/mysql/`
- **Format**: `tracker_backup_YYYY-MM-DD_HH-MM-SS.sql.gz`
- **Retention**: Configurable (default: 7 days)
## 🚀 Deployment Impact
### For Existing Deployments
- **Non-Breaking**: Backup automation is opt-in via environment variables
- **Default Disabled**: Production environments need explicit enablement
- **Resource Usage**: Minimal disk space and CPU impact
### For New Deployments
- **Enabled by Default**: Local development environments
- **Zero Configuration**: Works out-of-the-box with sensible defaults
- **Production Ready**: Full error handling and logging
## 📋 Migration Notes
### Environment Configuration
When deploying this update:
1. **Review backup settings** in your environment configuration
2. **Enable backups** if desired: `ENABLE_DB_BACKUPS=true`
3. **Adjust retention** if needed: `BACKUP_RETENTION_DAYS=14`
4. **Deploy normally** - backup setup is automatic
### Storage Requirements
- **Backup Size**: ~10-50KB for typical tracker databases
- **Daily Growth**: Minimal for tracker data
- **Monitoring**: Check `/home/torrust/backups/mysql/` periodically
## 🔄 What's Next (Post-Merge)
This PR completes **Phase 3** of Issue #21. The next phase will implement:
- **SSL Certificate Automation** (Let's Encrypt integration)
- **Certificate Renewal Automation** (Automatic renewal scripts)
- **Production SSL Configuration** (Nginx HTTPS setup)
## 🛡️ Security Considerations
- **Access Control**: Backup files have restricted permissions (600)
- **Data Protection**: Backups contain sensitive tracker data
- **Log Security**: No sensitive information logged
- **Process Isolation**: Backup runs as torrust user
## 📝 Files Changed
### New Files
- `application/share/bin/mysql-backup.sh` - Main backup script
- `docs/guides/database-backup-testing-guide.md` - Testing documentation
### Modified Files
- `infrastructure/scripts/deploy-app.sh` - Backup automation integration
- `infrastructure/config/environments/local.env` - Local environment config
- `infrastructure/config/environments/local.defaults` - Local defaults
- `infrastructure/config/templates/docker-compose.env.tpl` - Environment template
- `docs/issues/21-complete-application-installation-automation.md` - Progress tracking
---
**Ready for Review** ✅
All tests pass, documentation is complete, and the feature is fully functional.
---
**Part of Issue #21**: Complete Application Installation Automation
**Phase**: 3 - Database Backup Automation
**Next Phase**: SSL Certificate Automation
ACKs for top commit:
josecelano:
ACK bb0ba2e
Tree-SHA512: 468d0c3ce17d0678680c3fa8be5ad5cd5a29f16a82301b09b371053b7c213e943a972f55810bfb8b7a6253f6d9cc2e83d0ed5732853983d8949111607ab38a43
File tree
23 files changed
+3763
-120
lines changed- docs
- adr
- guides
- issues
- infrastructure
- config
- environments
- templates
- crontab
- scripts
23 files changed
+3763
-120
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | | - | |
61 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
62 | 62 | | |
63 | | - | |
64 | | - | |
65 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
108 | 111 | | |
109 | 112 | | |
110 | 113 | | |
| |||
153 | 156 | | |
154 | 157 | | |
155 | 158 | | |
156 | | - | |
| 159 | + | |
| 160 | + | |
157 | 161 | | |
158 | 162 | | |
159 | 163 | | |
| |||
162 | 166 | | |
163 | 167 | | |
164 | 168 | | |
| 169 | + | |
| 170 | + | |
165 | 171 | | |
166 | 172 | | |
167 | 173 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
56 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
57 | 61 | | |
58 | 62 | | |
59 | 63 | | |
| |||
Lines changed: 49 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| |||
116 | 117 | | |
117 | 118 | | |
118 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
119 | 133 | | |
120 | 134 | | |
121 | 135 | | |
| |||
183 | 197 | | |
184 | 198 | | |
185 | 199 | | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
186 | 207 | | |
187 | 208 | | |
188 | 209 | | |
| |||
249 | 270 | | |
250 | 271 | | |
251 | 272 | | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
252 | 301 | | |
253 | 302 | | |
254 | 303 | | |
| |||
0 commit comments