apps/dashboard/backend/app/clients/backrest_client.py aktualisiert
This commit is contained in:
@@ -7,7 +7,6 @@ from app.clients.base import BaseHTTPClient
|
||||
from app.config import Settings
|
||||
from app.models.sources import BackrestSnapshot
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -21,10 +20,11 @@ class BackrestClient(BaseHTTPClient):
|
||||
logger.info("backrest skipped: base URL missing")
|
||||
return snapshot
|
||||
|
||||
# Backrest uses Connect-RPC: POST /v1.Backrest/{Method}
|
||||
try:
|
||||
data = await self._request_json("GET", "/v1/config")
|
||||
data = await self._request_json("POST", "/v1.Backrest/GetConfig", json={})
|
||||
except Exception as exc:
|
||||
logger.warning("backrest fetch_status /v1/config failed: %s", exc)
|
||||
logger.warning("backrest fetch_status GetConfig failed: %s", exc)
|
||||
return snapshot
|
||||
|
||||
if not isinstance(data, dict):
|
||||
@@ -33,20 +33,22 @@ class BackrestClient(BaseHTTPClient):
|
||||
repos = data.get("repos") or []
|
||||
repo_count = len(repos) if isinstance(repos, list) else 0
|
||||
|
||||
# Fetch operation log for recent backup status
|
||||
# Fetch recent operations for backup status
|
||||
last_backup_age_hours: float | None = None
|
||||
error_count = 0
|
||||
last_backup_status = "unknown"
|
||||
|
||||
try:
|
||||
ops_data = await self._request_json(
|
||||
"POST", "/v1/operations",
|
||||
json={"last_n": 20},
|
||||
"POST",
|
||||
"/v1.Backrest/GetOperations",
|
||||
json={"lastN": 20},
|
||||
)
|
||||
ops = ops_data.get("operations") or [] if isinstance(ops_data, dict) else []
|
||||
# backupOp is a oneof field serialised directly at the operation level in proto3 JSON
|
||||
backup_ops = [
|
||||
op for op in ops
|
||||
if isinstance(op, dict) and op.get("op", {}).get("backupOp") is not None
|
||||
if isinstance(op, dict) and op.get("backupOp") is not None
|
||||
]
|
||||
error_ops = [op for op in backup_ops if op.get("status") == "STATUS_ERROR"]
|
||||
error_count = len(error_ops)
|
||||
@@ -59,10 +61,13 @@ class BackrestClient(BaseHTTPClient):
|
||||
now = datetime.now(timezone.utc)
|
||||
last_backup_age_hours = round((now - ended).total_seconds() / 3600, 1)
|
||||
status_str = latest.get("status", "")
|
||||
last_backup_status = "ok" if status_str == "STATUS_SUCCESS" else "error" if status_str == "STATUS_ERROR" else "unknown"
|
||||
|
||||
last_backup_status = (
|
||||
"ok" if status_str == "STATUS_SUCCESS"
|
||||
else "error" if status_str == "STATUS_ERROR"
|
||||
else "unknown"
|
||||
)
|
||||
except Exception as exc:
|
||||
logger.warning("backrest fetch_status /v1/operations failed: %s", exc)
|
||||
logger.warning("backrest fetch_status GetOperations failed: %s", exc)
|
||||
|
||||
return BackrestSnapshot(
|
||||
source_status="online",
|
||||
|
||||
Reference in New Issue
Block a user