From 06adc31bc94f2c718b9b131b59f5b5d2156cf6df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=94=AF=20A06?= Date: Thu, 3 Sep 2026 23:35:55 +0800 Subject: [PATCH] =?UTF-8?q?fix(sensor/backup):=20sensor=E5=8F=AA=E6=9F=A5a?= =?UTF-8?q?ctive=20cron(=E5=88=A0=E5=B7=B2=E5=88=A0cron=E8=AF=AF=E6=8A=A5)?= =?UTF-8?q?=20+=20=E5=8F=8C=E5=A4=87=E4=BB=BDmount=E5=89=8D=E6=8E=A2?= =?UTF-8?q?=E6=B4=BB=E9=98=B2=E6=8C=82=E8=B5=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - sensor-verify.py: check_exit_codes 只检查 jobs.json 中存在的 cron id, 忽略已删 cron(fdf92db462df/774986811686等)历史输出目录 → 消除误报链 - dual-backup.sh: mount cifs 前先 ping 探测(2s),不可达直接离线跳过; cifs 加 timeout=15 → 防 19:00 cron 超时 3600s 重演 - 清理传感器历史失败输出(fail链条归零) --- scripts/dual-backup.sh | 8 +++++++- scripts/sensor-verify.py | 18 +++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/scripts/dual-backup.sh b/scripts/dual-backup.sh index 5fba47fc..5589cd4a 100755 --- a/scripts/dual-backup.sh +++ b/scripts/dual-backup.sh @@ -36,10 +36,16 @@ log() { check_mount() { if ! mountpoint -q /mnt/server-backup; then log "⚠️ 服务器未挂载,尝试连接..." + # 2026-09-03:mount cifs 在服务器 TCP 不可达时会长时间挂起(19:00 cron 曾超时 3600s) + # → 先快速探测可达性(ping 1 次 2s 超时),不可达直接走"离线常态"跳过,避免 mount 挂起 + if ! ping -c 1 -W 2 192.168.188.11 >/dev/null 2>&1; then + log "ℹ️ 服务器不在局域网(常态),跳过本次备份" + return 2 + fi # -n: non-interactive,cron 环境无密码输入机会,立即失败不卡住 # || true: 失败是预期路径(服务器不在线),由下方 mountpoint 判断处理,避免 set -e 提前退出 sudo -n mount -t cifs //192.168.188.11/beifen /mnt/server-backup \ - -o username=administrator,password=xue.2538,uid=1000,gid=1000,iocharset=utf8,file_mode=0755,dir_mode=0755 2>/dev/null || true + -o username=administrator,password=xue.2538,uid=1000,gid=1000,iocharset=utf8,file_mode=0755,dir_mode=0755,timeout=15 2>/dev/null || true sleep 2 if ! mountpoint -q /mnt/server-backup; then log "ℹ️ 服务器不在局域网(常态),跳过本次备份" diff --git a/scripts/sensor-verify.py b/scripts/sensor-verify.py index 533bf805..6695dba1 100644 --- a/scripts/sensor-verify.py +++ b/scripts/sensor-verify.py @@ -78,13 +78,29 @@ def check_json_schema(): def check_exit_codes(): - """检查 cron 最近输出是否出现异常退出(Status: script failed / error)""" + """检查 cron 最近输出是否出现异常退出(Status: script failed / error) + 2026-09-03 修复:只检查当前 active cron(jobs.json 中存在的 id), + 忽略已删除 cron 的历史输出目录(避免误报)。 + """ issues = [] cron_out = HERMES + "/cron/output" if not os.path.isdir(cron_out): return issues + # 当前 active cron id 集合(jobs.json 为权威存储) + active_ids = set() + try: + with open(HERMES + "/cron/jobs.json", encoding="utf-8") as f: + data = json.load(f) + jobs = data.get("jobs", data) if isinstance(data, dict) else data + items = list(jobs.values()) if isinstance(jobs, dict) else jobs + active_ids = {str(j.get("id")) for j in items if isinstance(j, dict) and j.get("id")} + except Exception: + active_ids = set() # 读不到 jobs.json 时退化为检查全部(保守) cutoff = datetime.datetime.now() - datetime.timedelta(days=1) for jid in os.listdir(cron_out): + # 跳过已删除 cron 的残留输出目录 + if active_ids and jid not in active_ids: + continue jdir = os.path.join(cron_out, jid) if not os.path.isdir(jdir): continue