diff --git a/frappe/commands/site.py b/frappe/commands/site.py index 3e920cc0c2..ab7b337426 100644 --- a/frappe/commands/site.py +++ b/frappe/commands/site.py @@ -217,9 +217,29 @@ def _restore( with_public_files=None, with_private_files=None, ): + from pathlib import Path + from frappe.installer import extract_files from frappe.utils.backups import decrypt_backup, get_or_generate_backup_encryption_key + # 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) + err, out = frappe.utils.execute_in_shell(f"file {sql_file_path}", check_exit_code=True) if err: click.secho("Failed to detect type of backup file", fg="red") @@ -304,24 +324,6 @@ def restore_backup( 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.",