备份增量修复: 备份前服务器同步剪枝 (manifest 中服务器已删的批次移除, 文件重新纳入增量) - 解决'无增量更新'但服务器文件已删的问题
This commit is contained in:
@@ -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}: 无新增文件, 已是最新")
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ Package: 7z-encrypt-client
|
||||
Version: 1.0.0
|
||||
Architecture: all
|
||||
Maintainer: edgevoid <edgevoid@users.noreply.gitee.com>
|
||||
Installed-Size: 125
|
||||
Installed-Size: 126
|
||||
Depends: python3 (>= 3.10), python3-venv, p7zip-full
|
||||
Section: utils
|
||||
Priority: optional
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -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}: 无新增文件, 已是最新")
|
||||
|
||||
Reference in New Issue
Block a user