Cloud and Self-Hosting
ERPNext Backup and Restore with Frappe Bench: bench backup and bench restore Commands
By Amjid Ali · · Updated · 5 min read

In this article
To back up ERPNext, run bench --site yoursite backup --with-files from your frappe-bench folder: it saves the database, public files, private files and the site config to sites/yoursite/private/backups. To restore, run bench --site yoursite restore path/to/database.sql.gz --with-public-files path/to/files.tar --with-private-files path/to/private-files.tar, then bench --site yoursite migrate. The commands below work on ERPNext 13, 14, 15 and 16.
I restore the public demo at erp.syncbricks.com from a clean backup every night so testers always get fresh data, and I have moved client sites between servers with exactly these steps. The examples use the site erp.syncbricks.com; replace it with yours.
Quick reference
| Task | Command |
|---|---|
| Back up one site, database only | bench --site erp.syncbricks.com backup |
| Back up one site with all files | bench --site erp.syncbricks.com backup --with-files |
| Back up every site on the bench | bench --site all backup --with-files |
| Restore database only | bench --site erp.syncbricks.com restore DB.sql.gz |
| Restore database and files | bench --site erp.syncbricks.com restore DB.sql.gz --with-public-files FILES.tar --with-private-files PRIVATE.tar |
| Turn on automatic backups (cron) | bench setup backups |
| Apply schema after restore | bench --site erp.syncbricks.com migrate |
All commands run as the bench user from the frappe-bench directory.
What an ERPNext backup contains
The database alone is not a full backup. Attachments, images and generated files live on disk, and the site's encryption key lives in site_config.json. A full backup (--with-files) creates four files named with a timestamp and the site name:
| File | Contains |
|---|---|
20261018_020001-erp_syncbricks_com-database.sql.gz |
The MariaDB database dump |
20261018_020001-erp_syncbricks_com-files.tar |
Public files (website images, public attachments) |
20261018_020001-erp_syncbricks_com-private-files.tar |
Private files (most attachments) |
20261018_020001-erp_syncbricks_com-site_config_backup.json |
A copy of site_config.json, including encryption_key |
With --compress, the file archives are .tgz instead of .tar.
How to back up ERPNext with bench backup
cd ~/frappe-bench
bench --site erp.syncbricks.com backup --with-files --compress
ls -lh sites/erp.syncbricks.com/private/backups/
The command prints the path and size of each file when it finishes. All options, from the Frappe backup reference:
| Option | What it does |
|---|---|
--with-files |
Include public and private files |
--compress |
Save file archives as .tgz |
--backup-path |
Write all files to this folder |
--backup-path-db, --backup-path-conf, --backup-path-files, --backup-path-private-files |
Set the path for each file separately |
--exclude, -e |
DocTypes to leave out, comma-separated |
--only, --include, -i |
Back up only these DocTypes |
--ignore-backup-conf |
Ignore includes and excludes set in the site config |
--verbose |
More output |
Example: back up straight to a mounted NAS share.
bench --site erp.syncbricks.com backup --with-files --backup-path /mnt/nas/erpnext-backups
Automatic ERPNext backups
bench setup production runs bench setup backups, which adds a cron job for the bench user that runs bench --site all backup every 6 hours. Check it:
crontab -l
You should see a line ending in --site all backup >> .../logs/backup.log 2>&1 with the comment bench auto backups set for every 6 hours. If it is missing, run bench setup backups. To change the schedule or add --with-files, edit the line with crontab -e; my crontab guide explains the syntax.
ERPNext only keeps a few recent backups on disk (the "Number of Backups" setting in System Settings), and they sit on the same server they protect. Copy them somewhere else:
- S3 or S3-compatible storage: in ERPNext, search for S3 Backup Settings, add your bucket and keys, and enable the schedule. It works with AWS S3, Wasabi, Backblaze B2 or MinIO on a NAS.
- Google Drive or any rclone remote: run
rclone copyon the backups folder from cron. I use the same method for Proxmox in my rclone and Google Drive guide. - VM snapshots: if ERPNext runs on Proxmox, a nightly VM backup adds a second layer, but keep the bench backups too, because they restore onto any server.
How to restore ERPNext with bench restore
The format, from the Frappe restore reference:
bench --site [site-name] restore [OPTIONS] SQL_FILE_PATH
| Option | What it does |
|---|---|
--with-public-files PATH |
Restore public files from this archive |
--with-private-files PATH |
Restore private files from this archive |
--db-root-username, --db-root-password |
MariaDB root credentials (asked for if omitted) |
--db-name |
Database name, when restoring into a new site |
--admin-password |
Set the Administrator password after restoring |
--install-app |
Install an app after the restore |
--force |
Ignore the downgrade warning (not recommended) |
Restore the database and files
cd ~/frappe-bench
bench --site erp.syncbricks.com restore \
sites/erp.syncbricks.com/private/backups/20261018_020001-erp_syncbricks_com-database.sql.gz \
--with-public-files sites/erp.syncbricks.com/private/backups/20261018_020001-erp_syncbricks_com-files.tar \
--with-private-files sites/erp.syncbricks.com/private/backups/20261018_020001-erp_syncbricks_com-private-files.tar
bench --site erp.syncbricks.com migrate
There is no need to gunzip the .sql.gz first; current bench versions read it directly. When it finishes you will see Site erp.syncbricks.com has been restored with files. Then clear the cache and restart:
bench --site erp.syncbricks.com clear-cache
sudo supervisorctl restart all
Restore the database only
This is what I run every night on the demo: the data resets, the files stay.
bench --site erp.syncbricks.com restore /home/frappe/demo/clean-database.sql.gz --db-root-password "$DB_ROOT_PASSWORD"
Move ERPNext to a new server
- On the old server:
bench --site erp.example.com backup --with-files, then copy the four files to the new server (scporrsync). - On the new server, install the same major version of Frappe, ERPNext and any other apps the site uses (ERPNext 16 on Ubuntu 24.04).
- Create a site with the same name:
bench new-site erp.example.com, and install the same apps on it. - Copy
encryption_keyfrom the oldsite_config_backup.jsoninto the newsites/erp.example.com/site_config.json. - Restore with files as above, then
bench --site erp.example.com migrateandsudo supervisorctl restart all.
Moving the database to its own server instead? See ERPNext with an external MariaDB database.
Troubleshooting bench restore
Restore stops part way or fails with ERROR 1064. The SQL file is incomplete or the copy was interrupted. Compare its size with the original and check gunzip -t file.sql.gz.
Your site will be downgraded warning. The backup came from a newer version than the bench you are restoring into. Update the bench to that version first (bench update) rather than using --force, which can leave the schema broken.
ModuleNotFoundError or missing DocTypes after restore. The old site had apps (HRMS, custom apps) that the new bench does not. Run bench get-app and install-app for them, then migrate.
Encryption key is invalid or Decryption failed after restore. The new site has a different encryption_key. Copy the old one from site_config_backup.json into site_config.json.
Access denied for user 'root'@'localhost'. bench needs the MariaDB root password; pass --db-root-username and --db-root-password, or set a root password as shown in the installation guide.
Restore is very slow on a large database. Restore during a quiet window, and check free disk space with df -h: you need room for the unpacked SQL plus the database itself.
Related guides
- ERPNext installation methods compared
- ERPNext Docker installation: back up a Docker site with
docker compose exec backend bench --site frontend backup --with-files.
Frequently asked questions
How do I back up ERPNext?+
From the frappe-bench folder run bench --site yoursite backup --with-files. It writes a compressed database dump, public files, private files and a copy of site_config.json to sites/yoursite/private/backups. Copy those four files off the server to complete the backup.
What is the bench restore command?+
bench --site yoursite restore /path/to/xxxx-database.sql.gz --with-public-files /path/to/xxxx-files.tar --with-private-files /path/to/xxxx-private-files.tar. It asks for the MariaDB root password, replaces the site's database with the backup and unpacks the files. Run bench --site yoursite migrate afterwards.
Where are ERPNext backups stored?+
By default in sites/<site-name>/private/backups inside your frappe-bench directory, for example /home/frappe/frappe-bench/sites/erp.example.com/private/backups. You can change this per run with --backup-path.
Does ERPNext back up automatically?+
On a production bench, yes: bench setup production adds a cron job that runs bench --site all backup every 6 hours. Those backups stay on the same server, so also copy them off site, for example with the S3 Backup Settings in ERPNext or rclone.
Why are passwords broken after restoring ERPNext on a new server?+
Saved passwords such as email account and integration secrets are encrypted with the encryption_key in site_config.json. Copy the encryption_key from the old site's site_config.json (it is also in the site_config_backup.json file) into the new site before or after restoring, then restart bench.
How do I restore only the ERPNext database without files?+
Run bench --site yoursite restore /path/to/xxxx-database.sql.gz without the --with-public-files and --with-private-files options. Only the database is replaced; attachments already on disk stay as they are.
Related videos
Video library- Business and ERP
ERPNext Installation : Manual Install Ubuntu 20.04 Step by Step - Frappe Bench 13
· 22:01 · 31K views
Read the guide Watch on YouTube - Cloud and Self-Hosting
How to Backup and Restore LXC Containers in Proxmox
· 5:40 · 11K views
Watch on YouTube
Keep reading
Cloud and Self-HostingHow to Deploy a Flexible VPS for Apps: Kamatera ReviewNeed to deploy a flexible VPS for apps without committing to a fixed server shape? This Kamatera review examines its configurable cloud servers, scaling options, trial… · 8 min read
Cloud and Self-HostingExchange Server to Microsoft 365 Migration: A Pre-Migration Readiness ChecklistWhat to check before moving Exchange Server mailboxes to Microsoft 365: environment, migration method, identity, mail flow, permissions, security, pilot and cutover. · 7 min read
Cloud and Self-HostingList of Best Server Virtualization Software in ItalyA list of the best server virtualization software options for enterprises in Italy, compared on architecture, licensing, and security. · 5 min read