From df879ab1b81c01b8ff24a2239ee142e41d9dab1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Gruszczy=C5=84ski?= Date: Sun, 26 Oct 2025 21:46:21 +0100 Subject: [PATCH] backup before update --- npm_install.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/npm_install.py b/npm_install.py index 50c3aa4..6847443 100644 --- a/npm_install.py +++ b/npm_install.py @@ -2041,9 +2041,10 @@ def update_only( pj.write_text(txt, encoding="utf-8") # ========== BACKUP BEFORE UPDATE ========== + timestamp = time.strftime("%Y%m%d-%H%M%S") + backup_dir = Path(f"/data/backups/npm-backup-{timestamp}") + with step("Creating full backup before update"): - timestamp = time.strftime("%Y%m%d-%H%M%S") - backup_dir = Path(f"/data/backups/npm-backup-{timestamp}") backup_dir.parent.mkdir(parents=True, exist_ok=True) try: @@ -2057,7 +2058,6 @@ def update_only( if Path("/data/nginx").exists(): shutil.copytree("/data/nginx", backup_dir / "nginx", dirs_exist_ok=True) - # Save backup info backup_info = { "backup_date": timestamp, "npm_version": "current", @@ -2066,13 +2066,10 @@ def update_only( } (backup_dir / "backup_info.json").write_text(json.dumps(backup_info, indent=2)) - print(f" Backup saved to: {backup_dir}") - backups = sorted(backup_dir.parent.glob("npm-backup-*")) if len(backups) > 3: for old_backup in backups[:-3]: shutil.rmtree(old_backup, ignore_errors=True) - print(f" Removed old backup: {old_backup.name}") except Exception as e: print(f"⚠ Warning: Backup failed: {e}") @@ -2081,6 +2078,10 @@ def update_only( if response not in ["y", "yes"]: print("Update cancelled.") sys.exit(1) + + print(f" Backup location: {backup_dir}") + if len(backups) > 3: + print(f" Removed {len(backups) - 3} old backup(s)") # ========== END BACKUP ========== _build_frontend(src / "frontend", Path("/opt/npm/frontend"))