feat(compare): 核对结果写入 logs/ 并为 114 增加开机计划任务

- compare.py: 新增 write_report(),每次运行把报告以日志形式写到
  logs/compare_<granularity>_<日期>.log(含生成时间 + 汇总头部),
  --report 仍兼容作为额外输出路径
- main.py: compare 子命令改用 write_report,默认落 logs/,stdout 仍打印
- run_compare_ids.cmd: 114 主机开机计划任务包装脚本(ID 级核对)

Co-Authored-By: WorkBuddy <workbuddy@tencent.com>
This commit is contained in:
Misaka_Company
2026-07-17 11:06:21 +08:00
parent d71b7eab62
commit 75fb6a3a01
3 changed files with 65 additions and 6 deletions

17
main.py
View File

@@ -17,6 +17,7 @@ was launched or whether the venv already has ``src`` on its path.
from __future__ import annotations
import argparse
import logging
import os
import sys
@@ -27,9 +28,10 @@ from sync.config import load_config
from sync.logging_setup import setup_logging
from sync.fullsync import full_sync
from sync import service
from sync.compare import compare, any_mismatch, format_report
from sync.compare import compare, any_mismatch, format_report, write_report
CONFIG_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "config.yaml")
log = logging.getLogger("main")
def _parse_args(argv):
@@ -99,11 +101,14 @@ def main(argv=None) -> int:
if args.command == "compare":
results = compare(cfg, granularity=args.granularity,
db_filter=args.db, table_filter=args.table)
report = format_report(results, args.granularity)
print(report)
if args.report:
with open(args.report, "w", encoding="utf-8") as f:
f.write(report + "\n")
# Persist the report as a dated log file under the logging directory
# (logs/ by default); --report still allows an extra custom path.
log_dir = os.path.dirname((cfg.logging or {}).get("path", "sync.log")) or "."
written = write_report(results, args.granularity, log_dir=log_dir,
extra_path=args.report)
print(format_report(results, args.granularity))
log.info("compare finished (granularity=%s) report=%s mismatch=%s",
args.granularity, written, any_mismatch(results))
return 1 if any_mismatch(results) else 0
return 2 # unreachable: argparse requires a subcommand