What If I restore one site backup into another site?

My question is, I have a live instance and I want to import all its data into another instance for the testing purpose.

When I tried to restore the backup of one instance into another instance, then then it gives me error
raise Exception(“Database %s already exists” % (db_name,))
Exception: Database 1bd3e0294d already exists

What if, I create a new site and restore the backup into that site?
Will it work as it is as it is working in my live instance however, my live instance also have another site.

Regards
Ruchin Sharma

Add --force while restoring

1 Like

@rmehta
After trying

bench --force restore

I got this:

vishnu@vishnu-VirtualBox:~/frappe-bench$ bench --force restore /home/vishnu/frappe-bench/20160708_10266608_database.sql
MySQL root password:
Traceback (most recent call last):
File “/usr/lib/python2.7/runpy.py”, line 162, in _run_module_as_main
main”, fname, loader, pkg_name)
File “/usr/lib/python2.7/runpy.py”, line 72, in _run_code
exec code in run_globals
File “/home/vishnu/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 79, in
main()
File “/home/vishnu/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 16, in main
click.Group(commands=commands)(prog_name=‘bench’)
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 716, in call
return self.main(*args, **kwargs)
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 696, in main
rv = self.invoke(ctx)
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1060, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1060, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 889, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 534, in invoke
return callback(*args, **kwargs)
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py”, line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File “/home/vishnu/frappe-bench/apps/frappe/frappe/commands.py”, line 29, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File “/home/vishnu/frappe-bench/apps/frappe/frappe/commands.py”, line 130, in restore
_new_site(db_name, site, mariadb_root_username=mariadb_root_username, mariadb_root_password=mariadb_root_password, admin_password=admin_password, verbose=context.verbose, install_apps=install_app, source_sql=sql_file_path, force=context.force)
File “/home/vishnu/frappe-bench/apps/frappe/frappe/commands.py”, line 87, in _new_site
install_db(root_login=mariadb_root_username, root_password=mariadb_root_password, db_name=db_name, admin_password=admin_password, verbose=verbose, source_sql=source_sql,force=force, reinstall=reinstall)
File “/home/vishnu/frappe-bench/apps/frappe/frappe/installer.py”, line 39, in install_db
remove_missing_apps()
File “/home/vishnu/frappe-bench/apps/frappe/frappe/installer.py”, line 311, in remove_missing_apps
installed_apps = json.loads(frappe.db.get_global(“installed_apps”) or “[]”)
File “/home/vishnu/frappe-bench/apps/frappe/frappe/database.py”, line 642, in get_global
return self.get_default(key, user)
File “/home/vishnu/frappe-bench/apps/frappe/frappe/database.py”, line 654, in get_default
d = self.get_defaults(key, parent)
File “/home/vishnu/frappe-bench/apps/frappe/frappe/database.py”, line 660, in get_defaults
defaults = frappe.defaults.get_defaults(parent)
File “/home/vishnu/frappe-bench/apps/frappe/frappe/defaults.py”, line 72, in get_defaults
globald = get_defaults_for()
File “/home/vishnu/frappe-bench/apps/frappe/frappe/defaults.py”, line 179, in get_defaults_for
where parent = %s order by creation""", (parent,), as_dict=1)
File “/home/vishnu/frappe-bench/apps/frappe/frappe/database.py”, line 136, in sql
self._cursor.execute(query, values)
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/cursors.py”, line 205, in execute
self.errorhandler(self, exc, value)
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/connections.py”, line 36, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (1146, “Table ‘1bd3e0294d.tabDefaultValue’ doesn’t exist”)
vishnu@vishnu-VirtualBox:~/frappe-bench$

Any idea about how to resolve this?

Regards
Ruchin Sharma

try using bench restore --force, not bench --force restore

1 Like

@rmehta
After trying

bench restore --force

I am getting this error:
Error: no such option: --force

bench --force --site [your_site] restore ~/[databasepath].sql

4 Likes

@jof2jc

Try that too
vishnu@vishnu-VirtualBox:~/frappe-bench$ bench --force --site site1.local restore /home/vishnu/frappe-bench/20160708_10266608_database.sql
MySQL root password:
Traceback (most recent call last):
File “/usr/lib/python2.7/runpy.py”, line 162, in _run_module_as_main
main”, fname, loader, pkg_name)
File “/usr/lib/python2.7/runpy.py”, line 72, in _run_code
exec code in run_globals
File “/home/vishnu/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 79, in
main()
File “/home/vishnu/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 16, in main
click.Group(commands=commands)(prog_name=‘bench’)
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 716, in call
return self.main(*args, **kwargs)
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 696, in main
rv = self.invoke(ctx)
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1060, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1060, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 889, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 534, in invoke
return callback(*args, **kwargs)
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py”, line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File “/home/vishnu/frappe-bench/apps/frappe/frappe/commands.py”, line 29, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File “/home/vishnu/frappe-bench/apps/frappe/frappe/commands.py”, line 130, in restore
_new_site(db_name, site, mariadb_root_username=mariadb_root_username, mariadb_root_password=mariadb_root_password, admin_password=admin_password, verbose=context.verbose, install_apps=install_app, source_sql=sql_file_path, force=context.force)
File “/home/vishnu/frappe-bench/apps/frappe/frappe/commands.py”, line 87, in _new_site

HI @ruchin78

try below command
bench --site site1.local reinstall
bench --force --site site1.local restore /home/vishnu/frappe-bench/20160708_10266608_database.sql

Please check provided path of .sql file is correct

Thanks, Rohit

Hi Rohit,
I tried but it also didn’t work see the below errors:

vishnu@vishnu-VirtualBox:~/frappe-bench$ bench --site site1.local reinstall
Installing frappe…
Updating frappe : [========================================]
Updating country info : [========================================]
Set Administrator password:
Re-enter Administrator password:
Installing fixtures…
*** Scheduler is disabled ***
vishnu@vishnu-VirtualBox:~/frappe-bench$ bench --force --site site1.local restore /home/vishnu/frappe-bench/20160708_10266608_database.sql
MySQL root password:
Traceback (most recent call last):
File “/usr/lib/python2.7/runpy.py”, line 162, in _run_module_as_main
main”, fname, loader, pkg_name)
File “/usr/lib/python2.7/runpy.py”, line 72, in _run_code
exec code in run_globals
File “/home/vishnu/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 79, in
main()
File “/home/vishnu/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 16, in main
click.Group(commands=commands)(prog_name=‘bench’)
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 716, in call
return self.main(*args, **kwargs)
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 696, in main
rv = self.invoke(ctx)
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1060, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1060, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 889, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 534, in invoke
return callback(*args, **kwargs)
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py”, line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File “/home/vishnu/frappe-bench/apps/frappe/frappe/commands.py”, line 29, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File “/home/vishnu/frappe-bench/apps/frappe/frappe/commands.py”, line 130, in restore
_new_site(db_name, site, mariadb_root_username=mariadb_root_username, mariadb_root_password=mariadb_root_password, admin_password=admin_password, verbose=context.verbose, install_apps=install_app, source_sql=sql_file_path, force=context.force)
File “/home/vishnu/frappe-bench/apps/frappe/frappe/commands.py”, line 89, in _new_site
_install_app(“frappe”, verbose=verbose, set_as_patched=not source_sql)
File “/home/vishnu/frappe-bench/apps/frappe/frappe/installer.py”, line 93, in install_app
frappe.clear_cache()
File “/home/vishnu/frappe-bench/apps/frappe/frappe/init.py”, line 425, in clear_cache
for fn in frappe.get_hooks(“clear_cache”):
File “/home/vishnu/frappe-bench/apps/frappe/frappe/init.py”, line 721, in get_hooks
hooks = _dict(cache().get_value(“app_hooks”, load_app_hooks))
File “/home/vishnu/frappe-bench/apps/frappe/frappe/utils/redis_wrapper.py”, line 68, in get_value
val = generator()
File “/home/vishnu/frappe-bench/apps/frappe/frappe/init.py”, line 689, in load_app_hooks
for app in [app_name] if app_name else get_installed_apps(sort=True):
File “/home/vishnu/frappe-bench/apps/frappe/frappe/init.py”, line 669, in get_installed_apps
installed = json.loads(db.get_global(“installed_apps”) or “[]”)
File “/home/vishnu/frappe-bench/apps/frappe/frappe/database.py”, line 642, in get_global
return self.get_default(key, user)
File “/home/vishnu/frappe-bench/apps/frappe/frappe/database.py”, line 654, in get_default
d = self.get_defaults(key, parent)
File “/home/vishnu/frappe-bench/apps/frappe/frappe/database.py”, line 660, in get_defaults
defaults = frappe.defaults.get_defaults(parent)
File “/home/vishnu/frappe-bench/apps/frappe/frappe/defaults.py”, line 72, in get_defaults
globald = get_defaults_for()
File “/home/vishnu/frappe-bench/apps/frappe/frappe/defaults.py”, line 179, in get_defaults_for
where parent = %s order by creation""", (parent,), as_dict=1)
File “/home/vishnu/frappe-bench/apps/frappe/frappe/database.py”, line 136, in sql
self._cursor.execute(query, values)
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/cursors.py”, line 205, in execute
self.errorhandler(self, exc, value)
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/connections.py”, line 36, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (1146, “Table ‘1bd3e0294d.tabDefaultValue’ doesn’t exist”)
vishnu@vishnu-VirtualBox:~/frappe-bench$

Are you using Digital ocean servers?? if thats the case you can take a snapshot of your entire vps and spin up one more instance and perform all tests!!

@Basawaraj_Savalagi
I am using my local server.

Regards
Ruchin Sharma

@Basawaraj_Savalagi
@rohit_w
@jof2jc
@rmehta

Thanks a lot finally, I am able to restore the database with the below command:

bench --force --site site1.local restore /home/vishnu/frappe-bench/20160708_10266608_database.sql

But after restoring the database, when I tried run the ERPNext. It shows

Internal Server Error

I appreciate if anyone can help me in this context.

Regards
Ruchin Sharma

Did you run bench migrate after restore?

@jof2jc

After doing

bench migrate 

I got the below error:

vishnu@vishnu-VirtualBox:~/frappe-bench$ bench migrate
Migrating site1.local
Traceback (most recent call last):
File “/usr/lib/python2.7/runpy.py”, line 162, in _run_module_as_main
main”, fname, loader, pkg_name)
File “/usr/lib/python2.7/runpy.py”, line 72, in _run_code
exec code in run_globals
File “/home/vishnu/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 79, in
main()
File “/home/vishnu/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 16, in main
click.Group(commands=commands)(prog_name=‘bench’)
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 716, in call
return self.main(*args, **kwargs)
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 696, in main
rv = self.invoke(ctx)
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1060, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1060, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 889, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 534, in invoke
return callback(*args, **kwargs)
File “/home/vishnu/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py”, line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File “/home/vishnu/frappe-bench/apps/frappe/frappe/commands.py”, line 29, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File “/home/vishnu/frappe-bench/apps/frappe/frappe/commands.py”, line 205, in migrate
migrate(context.verbose, rebuild_website=rebuild_website)
File “/home/vishnu/frappe-bench/apps/frappe/frappe/migrate.py”, line 27, in migrate
frappe.modules.patch_handler.run_all()
File “/home/vishnu/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 23, in run_all
for patch in get_all_patches():
File “/home/vishnu/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 37, in get_all_patches
patches.extend(frappe.get_file_items(frappe.get_pymodule_path(app, “patches.txt”)))
File “/home/vishnu/frappe-bench/apps/frappe/frappe/init.py”, line 637, in get_pymodule_path
return os.path.join(os.path.dirname(get_module(scrub(modulename)).file), *joins)
File “/home/vishnu/frappe-bench/apps/frappe/frappe/init.py”, line 599, in get_module
return importlib.import_module(modulename)
File “/usr/lib/python2.7/importlib/init.py”, line 37, in import_module
import(name)
ImportError: No module named library

Regards
Ruchin Sharma

Try Installing library app in site1.local and then restore…

Hi,
@Basawaraj_Savalagi
It is already done by installing the app but I think I need to copy all the script files into the library app folder.

Regards
Ruchin Sharma