backup before update

This commit is contained in:
Mateusz Gruszczyński
2025-10-26 21:46:21 +01:00
parent cc07c03d82
commit df879ab1b8

View File

@@ -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"))