备份支持指定目录: sz-backup --dir <路径> (PC 端任意目录, 不限于预设项)
- backup() 加 srcs 参数: None=预设/配置目录, 显式传=备份指定目录 - CLI 加 --dir: 目录 basename 作为备份项名, restore 同名恢复 - TUI 菜单 13: 输入目录路径直接备份指定目录, 预设项不变
This commit is contained in:
@@ -110,16 +110,21 @@ def _cleanup(tar_path: Path) -> None:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def backup(name: str, chunk_mb: int = VOL_MB) -> int:
|
def backup(name: str, chunk_mb: int = VOL_MB, srcs: list[Path] | None = None) -> int:
|
||||||
"""整个文件夹 -> 单个 tar -> 32MB 卷压缩 (逐卷 7z + 逐卷加密) -> aria2 上传
|
"""整个文件夹 -> 单个 tar -> 32MB 卷压缩 (逐卷 7z + 逐卷加密) -> aria2 上传
|
||||||
|
|
||||||
一个文件夹 = 一个文件 (file_id), 不分批次。
|
一个文件夹 = 一个文件 (file_id), 不分批次。
|
||||||
|
srcs 为 None 时用预设/配置源目录 (photos/documents/...), 显式传入则
|
||||||
|
备份指定目录 (PC 端任意路径, 如 /home/lou/图片)。
|
||||||
"""
|
"""
|
||||||
from metadata import _build_vol_init
|
from metadata import _build_vol_init
|
||||||
import argparse as _ap
|
import argparse as _ap
|
||||||
from transfer import TransferClient
|
from transfer import TransferClient
|
||||||
|
|
||||||
|
if srcs is None:
|
||||||
srcs = [s for s in _src_dirs(name) if s.exists()]
|
srcs = [s for s in _src_dirs(name) if s.exists()]
|
||||||
|
else:
|
||||||
|
srcs = [s for s in srcs if s.is_dir()]
|
||||||
files = [p for s in srcs for p in s.rglob("*") if p.is_file()]
|
files = [p for s in srcs for p in s.rglob("*") if p.is_file()]
|
||||||
if not files:
|
if not files:
|
||||||
print(f"[备份] {name}: 源目录为空")
|
print(f"[备份] {name}: 源目录为空")
|
||||||
@@ -220,9 +225,10 @@ def list_backups() -> int:
|
|||||||
|
|
||||||
|
|
||||||
def main() -> int:
|
def main() -> int:
|
||||||
ap = argparse.ArgumentParser(description="一键备份: 相册/聊天记录/文档 -> 加密服务器")
|
ap = argparse.ArgumentParser(description="一键备份: 相册/聊天记录/文档/指定目录 -> 加密服务器")
|
||||||
ap.add_argument("action", nargs="?", default="all", help="备份项: photos/documents/download/chat/all/list/restore")
|
ap.add_argument("action", nargs="?", default="all", help="备份项: photos/documents/download/chat/all/list/restore")
|
||||||
ap.add_argument("target", nargs="?", help="restore 的备份项")
|
ap.add_argument("target", nargs="?", help="restore 的备份项")
|
||||||
|
ap.add_argument("--dir", help="备份指定目录 (不限于预设项, 如 /home/lou/图片)")
|
||||||
ap.add_argument("--chunk-size", type=int, default=VOL_MB, help=f"卷压缩 MB (默认 {VOL_MB})")
|
ap.add_argument("--chunk-size", type=int, default=VOL_MB, help=f"卷压缩 MB (默认 {VOL_MB})")
|
||||||
args = ap.parse_args()
|
args = ap.parse_args()
|
||||||
|
|
||||||
@@ -230,9 +236,15 @@ def main() -> int:
|
|||||||
return list_backups()
|
return list_backups()
|
||||||
if args.action == "restore":
|
if args.action == "restore":
|
||||||
if not args.target:
|
if not args.target:
|
||||||
print("[错误] 用法: sz-backup restore <photos|documents|download|chat>")
|
print("[错误] 用法: sz-backup restore <备份项名>")
|
||||||
return 1
|
return 1
|
||||||
return restore(args.target)
|
return restore(args.target)
|
||||||
|
if args.dir:
|
||||||
|
p = Path(args.dir).expanduser()
|
||||||
|
if not p.is_dir():
|
||||||
|
print(f"[错误] 目录不存在: {p}")
|
||||||
|
return 1
|
||||||
|
return backup(p.name, args.chunk_size, srcs=[p])
|
||||||
names = ["photos", "documents", "download", "chat"] if args.action == "all" else [args.action]
|
names = ["photos", "documents", "download", "chat"] if args.action == "all" else [args.action]
|
||||||
if args.action not in ("photos", "documents", "download", "chat", "all"):
|
if args.action not in ("photos", "documents", "download", "chat", "all"):
|
||||||
print(f"[错误] 未知备份项: {args.action} (photos/documents/download/chat/all)")
|
print(f"[错误] 未知备份项: {args.action} (photos/documents/download/chat/all)")
|
||||||
|
|||||||
Reference in New Issue
Block a user