diff --git a/app.py b/app.py index 80e44df..e460d79 100644 --- a/app.py +++ b/app.py @@ -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."""