Merge pull request #34263 from akhilnarang/fix-encrypted-restore-relative-path
fix: move backup file locating logic to `_restore()`
This commit is contained in:
commit
871ae70172
1 changed files with 20 additions and 18 deletions
|
|
@ -217,9 +217,29 @@ def _restore(
|
||||||
with_public_files=None,
|
with_public_files=None,
|
||||||
with_private_files=None,
|
with_private_files=None,
|
||||||
):
|
):
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from frappe.installer import extract_files
|
from frappe.installer import extract_files
|
||||||
from frappe.utils.backups import decrypt_backup, get_or_generate_backup_encryption_key
|
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)
|
err, out = frappe.utils.execute_in_shell(f"file {sql_file_path}", check_exit_code=True)
|
||||||
if err:
|
if err:
|
||||||
click.secho("Failed to detect type of backup file", fg="red")
|
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
|
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):
|
if is_partial(sql_file_path):
|
||||||
click.secho(
|
click.secho(
|
||||||
"Partial Backup file detected. You cannot use a partial file to restore a Frappe site.",
|
"Partial Backup file detected. You cannot use a partial file to restore a Frappe site.",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue