Files
voyager/collectors/backup.py
T

33 lines
664 B
Python

#!/usr/bin/env python3
import subprocess
import json
RESTIC_ENV = "/etc/restic/edge01.env"
def collect():
cmd = f'. "{RESTIC_ENV}" && restic snapshots --json'
result = subprocess.run(
["bash", "-c", cmd],
capture_output=True,
text=True,
)
if result.returncode != 0:
return {
"state": "offline",
"summary": "Restic error",
"detail": result.stderr.strip()
}
snapshots = json.loads(result.stdout)
return {
"state": "online",
"summary": "Healthy",
"detail": f"{len(snapshots)} snapshots",
"snapshot_count": len(snapshots)
}