feat: Borg-Archivhistorie je Host abfragen

This commit is contained in:
sascha 2026-08-05 14:16:44 +02:00
parent be01f03d3b
commit 7166ad9499

22
app.py
View file

@ -603,6 +603,28 @@ async def backup_break_lock(hostname: str, _=Depends(_verify)):
return {"status": "lock_broken", "hostname": hostname, "detail": out.strip()[-4000:]}
@app.get("/backup/history/{hostname}")
async def backup_history(hostname: str, _=Depends(_verify)):
"""Return the ten newest Borg archives for one inventory host."""
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)
rc, out, err = await asyncio.to_thread(
_ssh, f'{host["user"]}@{host["ip"]}',
"sudo -n borgmatic list --last 10 --json", 120
)
if rc != 0:
return JSONResponse(
{"error": "borg list failed", "hostname": hostname,
"stdout": out[-4000:], "stderr": err[-4000:]}, status_code=500
)
try:
history = json.loads(out)
except (TypeError, ValueError):
return JSONResponse({"error": "invalid borg JSON", "hostname": hostname}, status_code=500)
return {"hostname": hostname, "history": history}
@app.get("/backup/run-status/{hostname}")
async def backup_run_status(hostname: str, _=Depends(_verify)):
"""Lightweight current backup service state and recent logs."""