bench setup backups command configures a cron job to automatically back up all sites in your bench every 6 hours.
Usage
What It Does
Determine Cron User
Reads the
frappe_user from sites/common_site_config.json.If not set, uses the current system user.Backup Schedule
By default, backups run:- Every 6 hours (at 00:00, 06:00, 12:00, and 18:00)
- For all sites in the bench
- With verbose output logged to file
Examples
Basic Setup
Schedule automatic backups:Verify Cron Job
Check that the cron job was created:View Backup Logs
Monitor backup execution:Backup Files
Backup Location
Backups are stored in each site’s private directory:Backup Contents
Each backup includes:- Database backup: Compressed SQL dump (
.sql.gz) - Public files: Site files from
public/files(.tar) - Private files: Site files from
private/files(.tar)
Backup Naming
Format:YYYYMMDD_HHMMSS-[sitename]-[type].[ext]
Example:
Backup Configuration
Backup Retention
Configure how many backups to keep insite_config.json:
Exclude Files
Skip file backups (database only):Offsite Backups
S3 / AWS
Configure S3 for automatic offsite backups:Dropbox
Google Drive
Custom Backup Schedule
To customize the backup schedule, edit the cron job:Daily Backups
Run once daily at 2 AM:Hourly Backups
Run every hour:Weekly Backups
Run every Sunday at midnight:Multiple Backup Times
Run at 2 AM and 2 PM daily:Manual Backups
Backup All Sites
Backup Specific Site
Backup Without Files
Backup With Compression
Restore from Backup
Restore Database
Restore with Files
Monitoring
Check Backup Status
View recent backups:Backup Size
Check total backup size:Backup Age
Find backups older than 7 days:Troubleshooting
Backups Not Running
-
Check if cron job exists:
-
Check cron service:
-
Check backup logs:
Permission Issues
If backups fail with permission errors:Disk Space Issues
If backups fail due to insufficient disk space:Cron Not Running
If cron isn’t executing backups:Remove Backup Cron
To disable automatic backups:Best Practices
Test Restores Regularly
Test Restores Regularly
Periodically test backup restoration to ensure backups are valid:
Monitor Backup Size
Monitor Backup Size
Set up alerts for backup size anomalies:
Use Offsite Storage
Use Offsite Storage
Always maintain offsite backups:
- Configure S3, Dropbox, or Google Drive
- Use separate cloud provider from hosting
- Encrypt sensitive backups
- Test offsite backup restoration
Implement 3-2-1 Rule
Implement 3-2-1 Rule
Follow the 3-2-1 backup rule:
- 3 copies of data
- 2 different storage types
- 1 copy offsite
- Local server backups (automatic)
- S3 backups (automatic)
- Weekly manual backups to external drive
Related Commands
bench backup- Manually create backupsbench restore- Restore from backupbench --site all backup- Backup all sites
Source Code
Implementation:bench/bench.py:471
Command definition: bench/commands/setup.py:113