Backup System Overview
The system backs up two critical components:- Database Backups: Complete MySQL/MariaDB database snapshots
- Media Backups: All uploaded files (receipts, product images, payment receipts, etc.)
Configuration
Settings (settings.py)
Backup configuration frombar_galileo/settings.py:
File Structure
Backups are stored in:GPG Encryption Setup
Initial Setup
Generate GPG Key
Create a GPG keypair for encryption:
- Choose RSA and RSA (default)
- Key size: 4096 bits
- Expiration: 3 years or custom
- Name: Bar Galileo Backups
- Email: [email protected]
Verify Key Creation
GPG key details: RSA 4096, expires 2028-10-19, ID: E83D59F6FA84D04B
Exporting the GPG Key
For backup recovery on another server:Creating Backups
Web Interface (Recommended)
Choose Backup Type
Click one of the action buttons:
- Create Complete Backup: Database + Media
- Create DB Backup: Database only
- Create Media Backup: Media files only
Command Line
For manual or cron-based backups:Database Backup
Database Backup
Media Backup
Media Backup
Complete Backup (Custom Command)
Complete Backup (Custom Command)
The custom command
crear_backup_completo handles both backup types and solves issues with django-dbbackup’s encryption in version 5.0.0.Managing Backups
Viewing Backups
The backup list page shows:-
Database Backups:
- Filename (format:
YYYY-MM-DD-HHMMSS.psql.gpg) - Creation date and time
- File size (KB/MB)
- Download button
- Delete button
- Filename (format:
-
Media Backups:
- Filename (format:
YYYY-MM-DD-HHMMSS.media.zip.gpg) - Creation date and time
- File size (MB)
- Download button
- Delete button
- Filename (format:
-
Statistics:
- Total DB backups count
- Total media backups count
- Total storage used (MB)
Downloading Backups
Downloaded backups are encrypted. You’ll need the GPG private key to decrypt them.
Deleting Old Backups
Restoring Backups
Database Restore
Restore from Web Interface
- Navigate to Backups > Backup List
- Find the backup to restore
- Click Restore button
- Confirm the action
Media Restore
Restore from Web Interface
- Navigate to Backups > Backup List
- Find the media backup to restore
- Click Restore button
- Confirm the action
Permissions
The backup module requires these permissions:backups.ver: View backup list and statisticsbackups.crear: Create new backupsbackups.editar: Restore backups (modifies system)backups.eliminar: Delete backup files
Assign backup permissions carefully. These operations affect system integrity and should be restricted to administrators.
Automation with Cron
Setting Up Automated Backups
Create a cron job for daily backups:Adjust paths and timing based on your server configuration and business hours (schedule during low-traffic periods).
Best Practices
3-2-1 Backup Rule
3-2-1 Backup Rule
Maintain:
- 3 copies of data (production + 2 backups)
- 2 different storage types (local + cloud)
- 1 off-site backup (cloud, remote server, or physical location)
Test Restores Regularly
Test Restores Regularly
Perform quarterly restore tests on a staging environment to verify backup integrity and restore procedures.
Monitor Backup Size
Monitor Backup Size
Track backup file sizes over time. Sudden increases may indicate data issues or excessive growth.
Automate Everything
Automate Everything
Use cron jobs for consistent, hands-off backup creation. Manual backups are easily forgotten.
Secure GPG Keys
Secure GPG Keys
Store GPG private key in multiple secure locations (password manager, encrypted USB, safe deposit box).
Document Restore Process
Document Restore Process
Maintain step-by-step restore documentation for disaster recovery scenarios.
Troubleshooting
GPG Encryption Error
GPG Encryption Error
Symptom: Backup fails with GPG-related errorSolution:
- Verify GPG key exists:
gpg --list-keys - Ensure email matches
DBBACKUP_GPG_RECIPIENT - Test GPG encryption:
echo "test" | gpg -e -r [email protected]
Backup Directory Not Writable
Backup Directory Not Writable
Symptom: Permission denied when creating backupSolution:
Restore Fails with Database Lock
Restore Fails with Database Lock
Symptom: Cannot restore database - locked by active connectionsSolution:
- Stop Django server
- Close all database connections
- Run restore command
- Restart server
Media Backup Very Large
Media Backup Very Large
Symptom: Media backup exceeds expected sizeSolution:
- Check for old/unused files in
MEDIA_ROOT - Consider excluding temporary files from backup
- Use compression level 9 for maximum compression
Cannot Decrypt Backup
Cannot Decrypt Backup
Symptom: GPG decryption fails during restoreSolution:
- Verify GPG private key is imported:
gpg --list-secret-keys - If not, import:
gpg --import private.key - Ensure passphrase is correct
- Check key hasn’t expired
Backup Statistics API
The backup module provides a JSON API for statistics:Endpoint
Response Format
Use this API endpoint for monitoring dashboards or alerting systems.
File Upload Feature
The backup module supports uploading backup files:Next Steps: Learn about Reports & Analytics or explore Advanced Features.
