backup-all-sites command creates backups of all sites in the current bench, including database dumps and file backups.
Usage
What Gets Backed Up
For each site in the bench, the command backs up:- Database - Full SQL dump of the site’s database
- Private Files - Files in the site’s private directory
- Public Files - Files in the site’s public directory (optional)
Backup Location
Backups are stored in each site’ssites/[sitename]/private/backups/ directory:
Examples
Basic Backup
Backup Before Update
The
bench update command automatically backs up sites by default unless you use the --no-backup flag.Automated Backups with Cron
Backup Workflow
The command performs the following steps for each site:- Identify Sites - Lists all sites in the bench
- Create Backup Directory - Ensures backup directory exists
- Dump Database - Exports database to compressed SQL file
- Archive Files - Tars private files and optionally public files
- Backup Config - Saves site_config.json
- Verify - Confirms backup files were created
Comparison with Site-Specific Backup
backup-all-sites
- Backs up ALL sites
- No options available
- Faster for multiple sites
--site backup
- Backs up single site
- Supports flags (—with-files, etc.)
- More control per site
Site-Specific Options
For more control over individual site backups, use:Backup Management
List Backups
Delete Old Backups
Copy Backups Offsite
Restore from Backup
To restore a site from backup:Implementation Details
Location:bench/commands/utils.py:137
The command calls bench.utils.system.backup_all_sites() which:
- Iterates through all sites in the bench
- Invokes the backup process for each site
- Uses the same underlying backup logic as site-specific backups
- Reports success/failure for each site
Best Practices
Automate Regular Backups
Automate Regular Backups
Set up cron jobs to run backups automatically:
- Daily backups for production sites
- Weekly backups for development sites
- Before and after major updates
Store Backups Offsite
Store Backups Offsite
Don’t keep backups only on the same server:
- Use rsync to copy to another server
- Upload to cloud storage (S3, Google Cloud, etc.)
- Keep at least 3 copies in different locations
Test Restore Procedures
Test Restore Procedures
Regularly test that backups can be restored:
- Restore to a test environment monthly
- Document restore procedures
- Time how long restoration takes
Manage Backup Retention
Manage Backup Retention
Don’t let backups fill up disk space:
- Keep last 7 daily backups
- Keep last 4 weekly backups
- Keep last 12 monthly backups
- Delete older backups automatically
Troubleshooting
Disk Space Issues
Disk Space Issues
If backups are filling disk:
Permission Errors
Permission Errors
If you get permission denied:
MySQL Connection Errors
MySQL Connection Errors
If database backup fails:
Related Commands
bench --site [sitename] backup- Backup a specific site with optionsbench --site [sitename] restore- Restore a site from backup- bench update - Update command with automatic backup