π Complete Guide: Full Backup & Restore in Frappe / ERPNext (Production-Ready)
This article explains:
- β What a full backup really means in Frappe
- β Which backups are mandatory vs optional
- β How to restore safely (same site or new site)
- β οΈ Common mistakes & production caveats
- π§ Best practices used in real production systems
1οΈβ£ What βFull Backupβ Means in Frappe
A true full backup in Frappe consists of site-level data, not the entire bench by default.
πΉ Mandatory (Frappe-supported restore)
These are required for a complete site restore:
- Database
- Public files
- Private files
- Site configuration
πΉ Optional (Infrastructure / disaster recovery)
These are not required for restoring a site, but useful in some cases:
- Apps source code
- Bench config
- Logs
- Virtualenv
β οΈ Frappeβs official restore mechanism only understands site-level backups.
2οΈβ£ Mandatory Backup (Production β Recommended)
β Command: Full Site Backup (MUST DO)
bench --site yoursite.localhost backup --with-files
π What this creates
Location:
sites/yoursite.localhost/private/backups/
Files created:
| File | Purpose |
|---|---|
*-database.sql.gz |
All data (DocTypes, users, transactions) |
*-public-files.tar |
Public attachments, images, website assets |
*-private-files.tar |
Private files, reports, exports |
*-site_config_backup.json |
DB creds, encryption keys |
π This alone is sufficient to restore a site fully.
3οΈβ£ Optional Backup (Bench / Disaster Snapshot)
β οΈ Optional β NOT required for normal restore
This is useful if:
- You want a full server snapshot
- You canβt reinstall apps easily
- You want rollback protection
Optional command:
tar -czf frappe-bench-full-$(date +%F).tar.gz frappe-bench
β Includes apps β Includes configs β Includes everything
β Not used by bench restore
4οΈβ£ What You Should Back Up in Production (Summary)
| Item | Mandatory | Why |
|---|---|---|
| Database | β | Core data |
| Public files | β | Images, attachments |
| Private files | β | Confidential data |
| Site config | β | Encryption & DB access |
| Apps code | β | Can be reinstalled |
| Bench config | β | Re-creatable |
| Logs | β | Not data |
5οΈβ£ How to Restore a Site (Same Server / Same Name)
β οΈ Before restore
- Always restore from bench root
- App versions must match or be newer
- Restore must be uninterrupted
Step 1: Drop existing site (if exists)
bench drop-site yoursite.localhost
Step 2: Create empty site
bench new-site yoursite.localhost
Step 3: Install required apps (IMPORTANT)
Example:
bench --site yoursite.localhost install-app erpnext
Install all apps that existed at backup time.
Step 4: Restore database + files
bench --site yoursite.localhost restore \
sites/yoursite.localhost/private/backups/xxxx-database.sql.gz \
--with-public-files sites/yoursite.localhost/private/backups/xxxx-public-files.tar \
--with-private-files sites/yoursite.localhost/private/backups/xxxx-private-files.tar
Step 5: Migrate (MANDATORY)
bench --site yoursite.localhost migrate
bench restart
6οΈβ£ Restore Into a NEW Site (Cloning / Staging)
This is fully supported.
Example: Restore prod.localhost β staging.localhost
bench new-site staging.localhost
bench --site staging.localhost install-app erpnext
bench --site staging.localhost restore \
sites/prod.localhost/private/backups/xxxx-database.sql.gz \
--with-public-files sites/prod.localhost/private/backups/xxxx-public-files.tar \
--with-private-files sites/prod.localhost/private/backups/xxxx-private-files.tar
Then:
bench --site staging.localhost migrate
bench restart
7οΈβ£ What Is OPTIONAL During Restore?
| Item | Optional | When |
|---|---|---|
| Public files | β οΈ | If you donβt have them |
| Private files | β οΈ | If data is DB-only |
| Bench snapshot | β | Not used by restore |
| Same site name | β | Can restore to new site |
β οΈ If you donβt have a
public-files.tar, do not pass the flag.
8οΈβ£ Common Production Caveats (VERY IMPORTANT)
β 1. Version mismatch
Backup version must be β€ code version
β Newer code restoring older backup β OK β Older code restoring newer backup β risky
Always run:
bench migrate
β 2. Missing custom apps
Error:
ModuleNotFoundError: No module named 'customapp'
Fix:
- Install the app OR
- Recreate it with
bench new-app
β 3. Interrupting restore (Ctrl+C)
This causes:
- Half-created DB
- Broken schema
- Scheduler errors
Rule:
π If restore fails β bench drop-site and retry cleanly
β 4. Running bench from wrong directory
Always run from:
frappe-bench/
Not from:
sites/
9οΈβ£ Production Best Practices (Battle-Tested)
β Always do this
- Backup before migrate / update
- Store backups off-server
- Test restore once
- Use
--with-files
β Recommended automation
bench enable-scheduler
And sync:
sites/*/private/backups/
to:
- S3 / Wasabi
- rsync server
- Encrypted storage
π Final Recommendation
After any successful restore or upgrade:
bench --site yoursite.localhost backup --with-files
This ensures your next restore is painless.
π§ TL;DR
- Mandatory backup = site backup with files
- Bench snapshot = optional
- Restore requires apps installed
- Never interrupt restore
- Always migrate
- Always test once