feat: laufenden Borg-Job leichtgewichtig abfragen

This commit is contained in:
sascha 2026-08-05 14:10:20 +02:00
parent 6a9424be43
commit be01f03d3b

17
app.py
View file

@ -603,6 +603,23 @@ async def backup_break_lock(hostname: str, _=Depends(_verify)):
return {"status": "lock_broken", "hostname": hostname, "detail": out.strip()[-4000:]}
@app.get("/backup/run-status/{hostname}")
async def backup_run_status(hostname: str, _=Depends(_verify)):
"""Lightweight current backup service state and recent logs."""
host = await asyncio.to_thread(_find_inventory_host, hostname)
if not host or host["name"].startswith("node"):
return JSONResponse({"error": "inventory host not found"}, status_code=404)
command = """echo __STATE__
sudo -n systemctl show borg-backup.service -p ActiveState -p SubState -p Result -p ExecMainStatus --no-pager 2>&1
echo __LOGS__
sudo -n journalctl -u borg-backup.service -n 30 --no-pager 2>&1
"""
rc, out, err = await asyncio.to_thread(
_ssh, f'{host["user"]}@{host["ip"]}', command, 20
)
return {"hostname": hostname, "rc": rc, "output": out[-12000:], "stderr": err[-2000:]}
@app.post("/backup/run/{hostname}")
async def backup_run(hostname: str, _=Depends(_verify)):
"""Start one inventory host Borgmatic service asynchronously."""