Tutorial: Duplicate ERPNext site

I’m just finish duplicate site on ERPNext and want to share step for those who might need it in the future.

My use case is I want to duplicate site from staging-erp.aaa.com to erp.aaa.com and keep all the config and setting. So when staging-erp.aaa.com will be still running and will be use for testing and training and erp.aaa.com will be use for real transaction.

An additional step might be need to properly setup nginx domain, it’s depends on each setup.


Create new site

bench new-site erp.aaa.com

Copy site database

Site database name locate at bench/sites/site_name/site_config.json

mysqldump -h'mariadb' -u'root' -p source_database_name > site_data.sql
mysql -h'mariadb' -u'root' -p target_database_name < site_data.sql

Copy site file

rm -rf sites/erp.aaa.com/private/
rm -rf sites/erp.aaa.com/public/
cp -r sites/staging-erp.aaa.com/private/ sites/erp.aaa.com/private
cp -r sites/staging-erp.aaa.com/public/ sites/erp.aaa.com/public
20 Likes

please continue sharing your experience it’s very helpful
thank you @pipech

2 Likes

Thanks @pipech Must say very timely post. We are testing a site with loads of enhancement. With your tutorial we may not have to redo the whole setup again in production.

Some corporate environments move data from production server to staging area each night so that test environment always use the latest data. Thank you for the tutorial.

Is it possible to do an automatic daily cloning on a different VPS provider like DigitalOcean if your main site is on AWS?

thx for this guide, very much appreciated.

  1. out of curiousity … is there any particular reason you are not using bench backup / bench restore but mysql commands for the backup/restore procedure?
  2. mysqldump -h'mariadb' ... can be ... -h'localhost' ... alike, right?

I’ve tired to use bench backup / restore but it doesn’t work properly, there is an error when I tried to restore to new site.

Yes, -h’mariadb’ should be target mysql server each server will have different hostname.

It should be, but i think you need to take a look into MySQL Replication topic

command to restore db to existing site

bench --site mysite.localhost restore /path/to/dump/20200627_153338-mysite_localhost-database.sql.gz

command to restore db to non existing site

bench new-site mysite.localhost --source_sql /path/to/dump/20200627_153338-mysite_localhost-database.sql
3 Likes
bench new-site mysite.localhost --source_sql /path/to/dump/20200627_153338-mysite_localhost-database.sql

Work out nicely thanks !

1 Like

Does it also support restoring public and private files?

bench new-site cannot restore files. Check bench new-site --help

In docker there is a restore_backup.py script.

symlink it on non-docker frappe-bench and use.

Detail about how that script works frappe_docker/site-operations.md at main · frappe/frappe_docker · GitHub.

5 Likes