diff --git a/backup.py b/backup.py index b300d60..be57905 100644 --- a/backup.py +++ b/backup.py @@ -196,8 +196,33 @@ def _upload_tar(tar_path: Path, chunk_mb: int) -> str: return str(receipt["file_id"]) +def _prune_manifest(name: str, manifest: dict[str, Any]) -> None: + """服务器同步: 服务器已不存在的批次从 manifest 移除, 其文件重新纳入增量 + + 服务器文件被删 (手动/清理) 后 manifest 仍认为已备份会导致"无增量更新" + 但实际恢复不到——以服务器 file_id 为准剪枝, 下次备份自动重传。 + """ + from transfer import TransferClient + try: + client = TransferClient(_server(), token=_token()) + server_ids = {f["file_id"] for f in client.list_files()} + except Exception: + return # 服务器不可达: 保留 manifest, 不阻塞备份 + batches = manifest.get("batches", {}) + stale = [bn for bn, b in batches.items() if b.get("server_id") not in server_ids] + if not stale: + return + for bn in stale: + for fp in batches[bn].get("files", []): + manifest.setdefault("files", {}).pop(fp, None) + batches.pop(bn) + print(f"[备份] 服务器同步: 移除 {len(stale)} 个失效批次 (服务器文件已删), 将重新备份") + _save_manifest(name, manifest) + + def backup(name: str, chunk_mb: int = 10) -> int: manifest = _load_manifest(name) + _prune_manifest(name, manifest) files = _scan_new(name, manifest) if not files: print(f"[备份] {name}: 无新增文件, 已是最新") diff --git a/debian/7z-encrypt-client/DEBIAN/control b/debian/7z-encrypt-client/DEBIAN/control index 8eeb5e3..9c26585 100644 --- a/debian/7z-encrypt-client/DEBIAN/control +++ b/debian/7z-encrypt-client/DEBIAN/control @@ -2,7 +2,7 @@ Package: 7z-encrypt-client Version: 1.0.0 Architecture: all Maintainer: edgevoid -Installed-Size: 125 +Installed-Size: 126 Depends: python3 (>= 3.10), python3-venv, p7zip-full Section: utils Priority: optional diff --git a/debian/7z-encrypt-client/DEBIAN/md5sums b/debian/7z-encrypt-client/DEBIAN/md5sums index 87bdf84..f0de9a9 100644 --- a/debian/7z-encrypt-client/DEBIAN/md5sums +++ b/debian/7z-encrypt-client/DEBIAN/md5sums @@ -2,7 +2,7 @@ 440c53f84f5722b5146959c8fc6d7a23 usr/bin/sz-config ec8cf0df841e479689ccb681f6168ccc usr/bin/sz-transfer 0ba5b8147990daa7fd07344952c42847 usr/bin/sz-tui -1c8e2524738649398a4385a3f2a9e3c6 usr/share/7z-encrypt/backup.py +d0faeb4f34bb1cec041c9a4616e529be usr/share/7z-encrypt/backup.py dcb31e74e0a6ee8073337fc4fb2acf99 usr/share/7z-encrypt/config.py 8a064c0b3c21d50812a3fd69a320d862 usr/share/7z-encrypt/crypto.py 21062e04f8c7f4471881a39c489dfa73 usr/share/7z-encrypt/metadata.py diff --git a/debian/7z-encrypt-client/usr/share/7z-encrypt/backup.py b/debian/7z-encrypt-client/usr/share/7z-encrypt/backup.py index b300d60..be57905 100644 --- a/debian/7z-encrypt-client/usr/share/7z-encrypt/backup.py +++ b/debian/7z-encrypt-client/usr/share/7z-encrypt/backup.py @@ -196,8 +196,33 @@ def _upload_tar(tar_path: Path, chunk_mb: int) -> str: return str(receipt["file_id"]) +def _prune_manifest(name: str, manifest: dict[str, Any]) -> None: + """服务器同步: 服务器已不存在的批次从 manifest 移除, 其文件重新纳入增量 + + 服务器文件被删 (手动/清理) 后 manifest 仍认为已备份会导致"无增量更新" + 但实际恢复不到——以服务器 file_id 为准剪枝, 下次备份自动重传。 + """ + from transfer import TransferClient + try: + client = TransferClient(_server(), token=_token()) + server_ids = {f["file_id"] for f in client.list_files()} + except Exception: + return # 服务器不可达: 保留 manifest, 不阻塞备份 + batches = manifest.get("batches", {}) + stale = [bn for bn, b in batches.items() if b.get("server_id") not in server_ids] + if not stale: + return + for bn in stale: + for fp in batches[bn].get("files", []): + manifest.setdefault("files", {}).pop(fp, None) + batches.pop(bn) + print(f"[备份] 服务器同步: 移除 {len(stale)} 个失效批次 (服务器文件已删), 将重新备份") + _save_manifest(name, manifest) + + def backup(name: str, chunk_mb: int = 10) -> int: manifest = _load_manifest(name) + _prune_manifest(name, manifest) files = _scan_new(name, manifest) if not files: print(f"[备份] {name}: 无新增文件, 已是最新")