From 232da65e4c7696a051f79e07d19e8ae9c790c8b2 Mon Sep 17 00:00:00 2001 From: Akhil Narang Date: Fri, 5 Jan 2024 15:38:53 +0530 Subject: [PATCH] fix(restore): check backup directory and bench directory if we can't find the file Signed-off-by: Akhil Narang --- frappe/commands/site.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/frappe/commands/site.py b/frappe/commands/site.py index 9b2ad747a9..f016724f87 100644 --- a/frappe/commands/site.py +++ b/frappe/commands/site.py @@ -260,8 +260,28 @@ def restore_backup( admin_password, force, ): + from pathlib import Path + from frappe.installer import _new_site, is_downgrade, is_partial, validate_database_sql + # Check for the backup file in the backup directory, as well as the main bench directory + dirs = (f"{site}/private/backups", "..") + + # Try to resolve path to the file if we can't find it directly + if not Path(sql_file_path).exists(): + click.secho( + f"File {sql_file_path} not found. Trying to check in alternative directories.", fg="yellow" + ) + for dir in dirs: + potential_path = Path(dir) / Path(sql_file_path) + if potential_path.exists(): + sql_file_path = str(potential_path.resolve()) + click.secho(f"File {sql_file_path} found.", fg="green") + break + else: + click.secho(f"File {sql_file_path} not found.", fg="red") + sys.exit(1) + if is_partial(sql_file_path): click.secho( "Partial Backup file detected. You cannot use a partial file to restore a Frappe site.",