From 232da65e4c7696a051f79e07d19e8ae9c790c8b2 Mon Sep 17 00:00:00 2001 From: Akhil Narang Date: Fri, 5 Jan 2024 15:38:53 +0530 Subject: [PATCH 1/2] 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.", From b9923571dc82115bc2573a349a26046c3fb36b61 Mon Sep 17 00:00:00 2001 From: Akhil Narang Date: Mon, 8 Jan 2024 12:51:45 +0530 Subject: [PATCH 2/2] fix: check correct part of backup header `-- Backup generated by Frappe 15.1.0 on branch fix-backup-restore` Signed-off-by: Akhil Narang --- frappe/installer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frappe/installer.py b/frappe/installer.py index d96f1167f1..1215aa8e0e 100644 --- a/frappe/installer.py +++ b/frappe/installer.py @@ -757,8 +757,8 @@ def is_downgrade(sql_file_path, verbose=False): if backup_version is None: # This is likely an older backup, so try to extract another way header = get_db_dump_header(sql_file_path).split("\n") - if "Version" in header[0]: - backup_version = header[0].split(":")[-1].strip() + if match := re.search(r"Frappe (\d+\.\d+\.\d+)", header[0]): + backup_version = match.group(1) # Assume it's not a downgrade if we can't determine backup version if backup_version is None: