6.0 KiB
Database Backup System Documentation
Overview
The Quality Recticel application now includes a comprehensive database backup management system accessible from the Settings page for superadmin and admin users.
Features
1. Manual Backup
- Backup Now button creates an immediate full database backup
- Uses
mysqldumpto create complete SQL export - Includes all tables, triggers, routines, and events
- Each backup is timestamped:
backup_trasabilitate_YYYYMMDD_HHMMSS.sql
2. Scheduled Backups
Configure automated backups with:
- Enable/Disable: Toggle scheduled backups on/off
- Backup Time: Set time of day for automatic backup (default: 02:00)
- Frequency: Choose Daily, Weekly, or Monthly backups
- Retention Period: Automatically delete backups older than N days (default: 30 days)
3. Backup Management
- List Backups: View all available backup files with size and creation date
- Download: Download any backup file to your local computer
- Delete: Remove old or unnecessary backup files
- Restore: (Superadmin only) Restore database from a backup file
Configuration
Backup Path
The backup location can be configured in three ways (priority order):
-
Environment Variable (Docker):
# docker-compose.yml environment: BACKUP_PATH: /srv/quality_recticel/backups volumes: - /srv/docker-test/backups:/srv/quality_recticel/backups -
Configuration File:
# py_app/instance/external_server.conf backup_path=/srv/quality_app/backups -
Default Path:
/srv/quality_app/backups
.env Configuration
Add to your .env file:
BACKUP_PATH=/srv/docker-test/backups
Usage
Access Backup Management
- Login as superadmin or admin
- Navigate to Settings page
- Scroll to 💾 Database Backup Management card
- The backup management interface is only visible to superadmin/admin users
Create Manual Backup
- Click ⚡ Backup Now button
- Wait for confirmation message
- New backup appears in the list
Configure Scheduled Backups
- Check Enable Scheduled Backups
- Set desired backup time (24-hour format)
- Select frequency (Daily/Weekly/Monthly)
- Set retention period (days to keep backups)
- Click 💾 Save Schedule
Download Backup
- Locate backup in the list
- Click ⬇️ Download button
- File downloads to your computer
Delete Backup
- Locate backup in the list
- Click 🗑️ Delete button
- Confirm deletion
Restore Backup (Superadmin Only)
⚠️ WARNING: Restore will replace current database!
- This feature requires superadmin privileges
- API endpoint:
/api/backup/restore/<filename> - Use with extreme caution
Technical Details
Backup Module
Location: py_app/app/database_backup.py
Key Class: DatabaseBackupManager
Methods:
create_backup(): Create new backuplist_backups(): Get all backup filesdelete_backup(filename): Remove backup filerestore_backup(filename): Restore from backupget_backup_schedule(): Get current schedulesave_backup_schedule(schedule): Update schedulecleanup_old_backups(days): Remove old backups
API Endpoints
| Endpoint | Method | Access | Description |
|---|---|---|---|
/api/backup/create |
POST | Admin+ | Create new backup |
/api/backup/list |
GET | Admin+ | List all backups |
/api/backup/download/<filename> |
GET | Admin+ | Download backup file |
/api/backup/delete/<filename> |
DELETE | Admin+ | Delete backup file |
/api/backup/schedule |
GET/POST | Admin+ | Get/Set backup schedule |
/api/backup/restore/<filename> |
POST | Superadmin | Restore from backup |
Backup File Format
- Format: SQL dump file (
.sql) - Compression: Not compressed (can be gzip manually if needed)
- Contents: Complete database with structure and data
- Metadata: Stored in
backups_metadata.json
Schedule Storage
Schedule configuration stored in: {BACKUP_PATH}/backup_schedule.json
Example:
{
"enabled": true,
"time": "02:00",
"frequency": "daily",
"retention_days": 30
}
Security Considerations
- Access Control: Backup features restricted to admin and superadmin users
- Path Traversal Protection: Filenames validated to prevent directory traversal attacks
- Credentials: Database credentials read from
external_server.conf - Backup Location: Should be on different mount point than application for safety
Maintenance
Disk Space
Monitor backup directory size:
du -sh /srv/quality_app/backups
Manual Cleanup
Remove old backups manually:
find /srv/quality_app/backups -name "*.sql" -mtime +30 -delete
Backup Verification
Test restore in development environment:
mysql -u root -p trasabilitate < backup_trasabilitate_20251103_020000.sql
Troubleshooting
Backup Fails
- Check database credentials in
external_server.conf - Ensure
mysqldumpis installed - Verify write permissions on backup directory
- Check disk space availability
Scheduled Backups Not Running
- TODO: Implement scheduled backup daemon/cron job
- Check backup schedule is enabled
- Verify time format is correct (HH:MM)
Cannot Download Backup
- Check backup file exists
- Verify file permissions
- Ensure adequate network bandwidth
Future Enhancements
Planned Features (Task 4)
- Implement APScheduler for automated scheduled backups
- Add backup to external storage (S3, FTP, etc.)
- Email notifications for backup success/failure
- Backup compression (gzip)
- Incremental backups
- Backup encryption
- Backup verification tool
Support
For issues or questions about the backup system:
- Check application logs:
/srv/quality_app/logs/error.log - Verify backup directory permissions
- Test manual backup first before relying on scheduled backups
- Keep at least 2 recent backups before deleting old ones
Created: November 3, 2025
Module: Database Backup Management
Version: 1.0.0