From 6e31745290839826e5d8857e78a8d52ff3078317 Mon Sep 17 00:00:00 2001 From: Akhil Narang Date: Thu, 13 Feb 2025 16:04:02 +0530 Subject: [PATCH] chore: handle restoring gzipped backups Signed-off-by: Akhil Narang --- frappe/database/sqlite/setup_db.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/frappe/database/sqlite/setup_db.py b/frappe/database/sqlite/setup_db.py index c626f10fa0..63f0a717b0 100644 --- a/frappe/database/sqlite/setup_db.py +++ b/frappe/database/sqlite/setup_db.py @@ -54,7 +54,14 @@ def copy_db(db_file=None, verbose=False): destination_db_folder.mkdir() destination_db_path = destination_db_folder / f"{db_name}.db" - shutil.copy(db_path, destination_db_path) + if db_path.suffix == ".gz": + import gzip + + with gzip.open(db_file, "rb") as input, open(destination_db_path, "wb") as output: + shutil.copyfileobj(input, output) + + else: + shutil.copy(db_path, destination_db_path) if verbose: print("Imported from database {}".format(db_path))