Error Found during restore database in my localhost. how to solve it

erpadmin@erpnext:~$ sudo bench frappe --restore /home/Desktop/20150819_87182946_database.sql
[sudo] password for erpadmin:
frappe app is not installed. Run the following command to install frappe
bench get-app frappe https://github.com/frappe/frappe.git
Traceback (most recent call last):
File “/usr/local/bin/bench”, line 9, in
load_entry_point(‘bench==0.92’, ‘console_scripts’, ‘bench’)()
File “/home/erpadmin/bench-repo/bench/cli.py”, line 46, in cli
return old_frappe_cli()
File “/home/erpadmin/bench-repo/bench/cli.py”, line 98, in old_frappe_cli
os.execv(f, [f] + sys.argv[2:])
OSError: [Errno 2] No such file or directory
erpadmin@erpnext:~$

Considering you are using frappe 5. There is no bench frappe.

Goto frappe-bench & execute

bench restore /home/Desktop/20150819_87182946_database.sql

i have try above command but following error found

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/erpadmin/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 77, in
main()
File “/home/erpadmin/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 14, in main
click.Group(commands=commands)(prog_name=‘bench’)
File “/home/erpadmin/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 700, in call
return self.main(*args, **kwargs)
File “/home/erpadmin/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 680, in main
rv = self.invoke(ctx)
File “/home/erpadmin/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1027, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/erpadmin/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1027, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/erpadmin/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 873, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/erpadmin/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 508, in invoke
return callback(*args, **kwargs)
File “/home/erpadmin/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py”, line 16, in new_func
return f(get_current_context(), *args, **kwargs)
File “/home/erpadmin/frappe-bench/apps/frappe/frappe/commands.py”, line 27, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File “/home/erpadmin/frappe-bench/apps/frappe/frappe/commands.py”, line 129, 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/erpadmin/frappe-bench/apps/frappe/frappe/commands.py”, line 85, 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/erpadmin/frappe-bench/apps/frappe/frappe/installer.py”, line 31, in install_db
create_database_and_user(force, verbose)
File “/home/erpadmin/frappe-bench/apps/frappe/frappe/installer.py”, line 53, in create_database_and_user
raise Exception(“Database %s already exists” % (db_name,))
Exception: Database 1bd3e0294d already exists
root@erpnext:/home/erpadmin/frappe-bench#

From mysql prompt, drop the database and re-execute bench restore /home/Desktop/20150819_87182946_database.sql

or use bench --force restore {sql file}

2 Likes

I have apply to force restore command found following error


MySQL root password:
sh: 1: cannot open 20150819_87182946_database.sql: No such file
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/erpadmin/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 77, in
main()
File “/home/erpadmin/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 14, in main
click.Group(commands=commands)(prog_name=‘bench’)
File “/home/erpadmin/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 700, in call
return self.main(*args, **kwargs)
File “/home/erpadmin/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 680, in main
rv = self.invoke(ctx)
File “/home/erpadmin/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1027, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/erpadmin/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1027, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/erpadmin/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 873, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/erpadmin/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 508, in invoke
return callback(*args, **kwargs)
File “/home/erpadmin/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py”, line 16, in new_func
return f(get_current_context(), *args, **kwargs)
File “/home/erpadmin/frappe-bench/apps/frappe/frappe/commands.py”, line 27, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File “/home/erpadmin/frappe-bench/apps/frappe/frappe/commands.py”, line 129, 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/erpadmin/frappe-bench/apps/frappe/frappe/commands.py”, line 85, 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/erpadmin/frappe-bench/apps/frappe/frappe/installer.py”, line 38, in install_db
remove_missing_apps()
File “/home/erpadmin/frappe-bench/apps/frappe/frappe/installer.py”, line 234, in remove_missing_apps
installed_apps = json.loads(frappe.db.get_global(“installed_apps”) or “[]”)
File “/home/erpadmin/frappe-bench/apps/frappe/frappe/database.py”, line 625, in get_global
return self.get_default(key, user)
File “/home/erpadmin/frappe-bench/apps/frappe/frappe/database.py”, line 637, in get_default
d = frappe.defaults.get_defaults(parent).get(key)
File “/home/erpadmin/frappe-bench/apps/frappe/frappe/defaults.py”, line 49, in get_defaults
globald = get_defaults_for()
File “/home/erpadmin/frappe-bench/apps/frappe/frappe/defaults.py”, line 154, in get_defaults_for
where parent = %s order by creation""", (parent,), as_dict=1)
File “/home/erpadmin/frappe-bench/apps/frappe/frappe/database.py”, line 135, in sql
self._cursor.execute(query, values)
File “/home/erpadmin/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/cursors.py”, line 205, in execute
self.errorhandler(self, exc, value)
File “/home/erpadmin/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”)
root@erpnext:/home/erpadmin/frappe-bench# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 203
Server version: 10.0.21-MariaDB-1~trusty-log mariadb.org binary distribution

Copyright © 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

MariaDB [(none)]> show databases;
±-------------------+
| Database |
±-------------------+
| 1bd3e0294d |
| information_schema |
| mysql |
| performance_schema |
±-------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]>

Did you unzip your backup file using gunzip dbfile.sql.gz?

I unzip file first
second remove 1bd3e0294d Database
MariaDB [(none)]> show databases;
±-------------------+
| Database |
±-------------------+
| information_schema |
| mysql |
| performance_schema |
±-------------------+
3 rows in set (0.00 sec)

And run…But found again following error

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/erpadmin/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 77, in
main()
File “/home/erpadmin/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 14, in main
click.Group(commands=commands)(prog_name=‘bench’)
File “/home/erpadmin/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 700, in call
return self.main(*args, **kwargs)
File “/home/erpadmin/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 680, in main
rv = self.invoke(ctx)
File “/home/erpadmin/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1027, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/erpadmin/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1027, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/erpadmin/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 873, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/erpadmin/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 508, in invoke
return callback(*args, **kwargs)
File “/home/erpadmin/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py”, line 16, in new_func
return f(get_current_context(), *args, **kwargs)
File “/home/erpadmin/frappe-bench/apps/frappe/frappe/commands.py”, line 27, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File “/home/erpadmin/frappe-bench/apps/frappe/frappe/commands.py”, line 129, 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/erpadmin/frappe-bench/apps/frappe/frappe/commands.py”, line 85, 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/erpadmin/frappe-bench/apps/frappe/frappe/installer.py”, line 31, in install_db
create_database_and_user(force, verbose)
File “/home/erpadmin/frappe-bench/apps/frappe/frappe/installer.py”, line 53, in create_database_and_user
raise Exception(“Database %s already exists” % (db_name,))
Exception: Database 1bd3e0294d already exists
erpadmin@erpnext:~$

Seems strange. Try removing the “create database” line from your database dump (.sql file)