fix(sensor/backup): sensor只查active cron(删已删cron误报) + 双备份mount前探活防挂起
- 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链条归零)
This commit is contained in:
parent
7439c5806b
commit
06adc31bc9
|
|
@ -36,10 +36,16 @@ log() {
|
||||||
check_mount() {
|
check_mount() {
|
||||||
if ! mountpoint -q /mnt/server-backup; then
|
if ! mountpoint -q /mnt/server-backup; then
|
||||||
log "⚠️ 服务器未挂载,尝试连接..."
|
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 环境无密码输入机会,立即失败不卡住
|
# -n: non-interactive,cron 环境无密码输入机会,立即失败不卡住
|
||||||
# || true: 失败是预期路径(服务器不在线),由下方 mountpoint 判断处理,避免 set -e 提前退出
|
# || true: 失败是预期路径(服务器不在线),由下方 mountpoint 判断处理,避免 set -e 提前退出
|
||||||
sudo -n mount -t cifs //192.168.188.11/beifen /mnt/server-backup \
|
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
|
sleep 2
|
||||||
if ! mountpoint -q /mnt/server-backup; then
|
if ! mountpoint -q /mnt/server-backup; then
|
||||||
log "ℹ️ 服务器不在局域网(常态),跳过本次备份"
|
log "ℹ️ 服务器不在局域网(常态),跳过本次备份"
|
||||||
|
|
|
||||||
|
|
@ -78,13 +78,29 @@ def check_json_schema():
|
||||||
|
|
||||||
|
|
||||||
def check_exit_codes():
|
def check_exit_codes():
|
||||||
"""检查 cron 最近输出是否出现异常退出(Status: script failed / error)"""
|
"""检查 cron 最近输出是否出现异常退出(Status: script failed / error)
|
||||||
|
2026-09-03 修复:只检查当前 active cron(jobs.json 中存在的 id),
|
||||||
|
忽略已删除 cron 的历史输出目录(避免误报)。
|
||||||
|
"""
|
||||||
issues = []
|
issues = []
|
||||||
cron_out = HERMES + "/cron/output"
|
cron_out = HERMES + "/cron/output"
|
||||||
if not os.path.isdir(cron_out):
|
if not os.path.isdir(cron_out):
|
||||||
return issues
|
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)
|
cutoff = datetime.datetime.now() - datetime.timedelta(days=1)
|
||||||
for jid in os.listdir(cron_out):
|
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)
|
jdir = os.path.join(cron_out, jid)
|
||||||
if not os.path.isdir(jdir):
|
if not os.path.isdir(jdir):
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue