Polish mobile shopping rows and stabilize backup archives

This commit is contained in:
2026-04-16 15:31:52 +02:00
parent 5e9beb1d98
commit 43fdd7081c
3 changed files with 81 additions and 10 deletions
+15 -3
View File
@@ -52,13 +52,25 @@ def export_backup_archive(
payload["tables"][table_name] = [dict(row) for row in rows]
uploads_root = Path(upload_folder)
with zipfile.ZipFile(archive_path, "w", compression=zipfile.ZIP_DEFLATED) as archive:
archive.writestr("backup.json", json.dumps(payload, ensure_ascii=False, indent=2))
uploads_snapshot_dir = Path(tempfile.mkdtemp(prefix="nouri-backup-uploads-"))
try:
if uploads_root.exists():
for file_path in uploads_root.rglob("*"):
if not file_path.is_file():
continue
relative_path = file_path.relative_to(uploads_root)
snapshot_path = uploads_snapshot_dir / relative_path
snapshot_path.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(file_path, snapshot_path)
with zipfile.ZipFile(archive_path, "w", compression=zipfile.ZIP_DEFLATED) as archive:
archive.writestr("backup.json", json.dumps(payload, ensure_ascii=False, indent=2))
for file_path in uploads_snapshot_dir.rglob("*"):
if file_path.is_file():
relative_path = file_path.relative_to(uploads_root)
relative_path = file_path.relative_to(uploads_snapshot_dir)
archive.write(file_path, f"uploads/{relative_path.as_posix()}")
finally:
shutil.rmtree(uploads_snapshot_dir, ignore_errors=True)
return archive_path, backup_name