Error using bench restore after bench migrate on Frappe v14.43.0 & v14.49.0

Hello Frappe community!

I’m encountering an issue when trying to restore a backup using the bench restore command. Here’s the traceback for the error I’m receiving:

(env) frappe@ff2087e43cb5:/workspace/development/frappe-bench$ bench restore /workspace/development/frappe-bench/sites/development.localhost/private/backups/20230915_010323-development_localhost-database.sql.gz 
Traceback (most recent call last):
  File "/home/frappe/.pyenv/versions/3.10.12/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/frappe/.pyenv/versions/3.10.12/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/workspace/development/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 109, in <module>
    main()
  File "/workspace/development/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
    click.Group(commands=commands)(prog_name="bench")
  File "/workspace/development/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/workspace/development/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/workspace/development/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/workspace/development/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/workspace/development/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/workspace/development/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/workspace/development/frappe-bench/env/lib/python3.10/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/workspace/development/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 29, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/workspace/development/frappe-bench/apps/frappe/frappe/commands/site.py", line 202, in restore
    if not force and is_downgrade(decompressed_file_name, verbose=True):
  File "/workspace/development/frappe-bench/apps/frappe/frappe/installer.py", line 789, in is_downgrade
    app_rows = frappe.safe_eval(line)
  File "/workspace/development/frappe-bench/apps/frappe/frappe/__init__.py", line 2279, in safe_eval
    return safe_eval(code, eval_globals, eval_locals)
  File "/workspace/development/frappe-bench/apps/frappe/frappe/utils/safe_exec.py", line 99, in safe_eval
    _validate_safe_eval_syntax(code)
  File "/workspace/development/frappe-bench/apps/frappe/frappe/utils/safe_exec.py", line 117, in _validate_safe_eval_syntax
    tree = ast.parse(code, mode="eval")
  File "/home/frappe/.pyenv/versions/3.10.12/lib/python3.10/ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
  File "<unknown>", line 0
    
SyntaxError: invalid syntax

Additional details:

  • Frappe Framework Versions Tested: v14.43.0 (version-14) and v14.49.0
  • Python Version: 3.10.12 (as seen from the traceback)
  • The issue arises after performing a bench migrate.
  • I’ve tried a fresh installation with only the Frappe framework, and the issue persists.

Any insights or guidance on what might be causing this and how to resolve it would be greatly appreciated.

Thank you in advance for your support!

Please mention site_name in restore command

bench --site {site} restore {path/to/database/file}

eg :-

bench --site development.localhost restore /workspace/development/frappe-bench/sites/development.localhost/private/backups/20230915_010323-development_localhost-database.sql.gz

I didn’t specify the site name during the restore because I’ve already set it as the default with bench use [site-name]. It’s worth noting that I’m not new to using this command, and my setup is within a Docker environment.

Additionally, it’s important to point out that the restore command works seamlessly with backups created prior to running bench migrate. Otherwise, you might have to force the restoration.

I face the same issue now. Could you already solve it?

Removing the following lines from the backup resolves the error and allows for a successful restore:
INSERT INTO tabInstalled Application VALUES ('395eb762aa','2023-09-15 09:58:54.927698','2023-09-15 09:58:54.927698','Administrator','Administrator',0,1,'frappe','14.49.0','version-14','Installed Applications','installed_applications','Installed Applications'), ('fe1a7e895f','2023-09-15 09:58:54.929526','2023-09-15 09:58:54.929526','Administrator','Administrator',0,2,'erpnext','14.39.0','version-14','Installed Applications','installed_applications','Installed Applications');

Error using bench restore after bench migrate on Frappe v14 · Issue #22430 · frappe/frappe (github.com)

1 Like

I also ran into this issue, although some slight differences apply. The error produced looks like this:

$ bench --site training.localhost restore ~/BACKUPS/20231101_180125-training_localhost-database.sql.gz                                    1 ⨯
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/pentest/frappe/training/apps/frappe/frappe/utils/bench_helper.py", line 114, in <module>
    main()
  File "/home/pentest/frappe/training/apps/frappe/frappe/utils/bench_helper.py", line 20, in main
    click.Group(commands=commands)(prog_name="bench")
  File "/home/pentest/frappe/training/env/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pentest/frappe/training/env/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/pentest/frappe/training/env/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pentest/frappe/training/env/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pentest/frappe/training/env/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pentest/frappe/training/env/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pentest/frappe/training/env/lib/python3.11/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pentest/frappe/training/apps/frappe/frappe/commands/__init__.py", line 29, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pentest/frappe/training/apps/frappe/frappe/commands/site.py", line 147, in restore
    _restore(
  File "/home/pentest/frappe/training/apps/frappe/frappe/commands/site.py", line 238, in _restore
    if not force and is_downgrade(decompressed_file_name, verbose=True):
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pentest/frappe/training/apps/frappe/frappe/installer.py", line 787, in is_downgrade
    app_rows = frappe.safe_eval(line)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pentest/frappe/training/apps/frappe/frappe/__init__.py", line 2277, in safe_eval
    return safe_eval(code, eval_globals, eval_locals)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pentest/frappe/training/apps/frappe/frappe/utils/safe_exec.py", line 103, in safe_eval
    _validate_safe_eval_syntax(code)
  File "/home/pentest/frappe/training/apps/frappe/frappe/utils/safe_exec.py", line 121, in _validate_safe_eval_syntax
    tree = ast.parse(code, mode="eval")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<unknown>", line 0
    
SyntaxError: invalid syntax

It’s a manual installation in development mode. It was current at the time (updated each day or so). The date of the backup file shows the approximate date of occurrence of the problem. So unlike with the OP’s installation, it’s on the 15 dev version.

What prompted my restore attempt was that I noticed some doctypes were gone. They became orphaned due to a currently still unknown reason. They were subsequently automatically removed by a bench update (or migrate, don’t remember exactly). Then I tried the restore, but unsuccessfully.

The error message is not the original one but one I did just moments ago. I tried restoring a backup from before the orphanage problem.

Strangely, it’s just the doctypes that disappeared. The data seems to be still in the database (seemingly unchanged – maybe fortunately in my case – because the restore failed, pending further investigation).

The json files of the disappeared doctypes (from dev mode) are gone, but since this occurred during a training exercise, some of them were copied in time for a submission.

Note that this was raised as an issue on github already (see post above):

which seems to be still unresolved.

A non-working restore can be painful … as can be disappearing doctypes.