Merge pull request #24145 from akhilnarang/fix-backup-restore

fix(restore): check backup directory and bench directory if we can't find the file
This commit is contained in:
Akhil Narang 2024-01-08 17:42:58 +05:30 committed by GitHub
commit ebdf88150d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View file

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

View file

@ -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: