fix: move backup file locating logic to _restore()

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
Akhil Narang 2025-10-04 16:51:55 +05:30
parent b5ecb1ef00
commit 7e61d71817
No known key found for this signature in database
GPG key ID: 9DCC61E211BF645F

View file

@ -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.",