56 lines
1.9 KiB
Bash
Executable File
56 lines
1.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
API_URL="${API_URL:-http://127.0.0.1:8080}"
|
|
|
|
python3 - "$API_URL" <<'PY'
|
|
import json
|
|
import sys
|
|
import urllib.error
|
|
import urllib.request
|
|
|
|
api = sys.argv[1].rstrip("/")
|
|
|
|
def request(method, path, body=None):
|
|
data = None if body is None else json.dumps(body).encode()
|
|
req = urllib.request.Request(
|
|
api + path,
|
|
data=data,
|
|
method=method,
|
|
headers={"Content-Type": "application/json"},
|
|
)
|
|
try:
|
|
with urllib.request.urlopen(req, timeout=30) as res:
|
|
return json.loads(res.read().decode())
|
|
except urllib.error.HTTPError as exc:
|
|
raise SystemExit(f"{method} {path} failed: {exc.code} {exc.read().decode()}") from exc
|
|
|
|
settings = request("GET", "/api/settings")
|
|
if settings.get("proxmox_storage") != "hitachi":
|
|
raise SystemExit("Expected configured Proxmox storage to be 'hitachi'")
|
|
if settings.get("local_backup_dir") != "/mnt/pve/hitachi/dump":
|
|
raise SystemExit("Expected configured local backup directory to be '/mnt/pve/hitachi/dump'")
|
|
|
|
guests = request("GET", "/api/guests")
|
|
guest = next((g for g in guests if int(g["vmid"]) == 110 and g["name"] == "adguard"), None)
|
|
if not guest:
|
|
raise SystemExit("Expected Proxmox guest adguard with VMID 110")
|
|
|
|
job = request("POST", "/api/jobs", {
|
|
"guest_vmid": 110,
|
|
"guest_name": "adguard",
|
|
"guest_type": guest["type"],
|
|
"node": guest["node"],
|
|
"enabled": False,
|
|
"cron_schedule": "0 3 * * *",
|
|
"proxmox_storage": "hitachi",
|
|
"backup_mode": settings["default_backup_mode"],
|
|
"compression": settings["default_compression"],
|
|
"retention_type": "days",
|
|
"retention_value": 1,
|
|
})
|
|
backup = request("POST", f"/api/jobs/{job['id']}/run")
|
|
print(json.dumps({"job": job, "queued_backup": backup}, indent=2))
|
|
print("Queued integration backup for adguard VMID 110 on storage hitachi (/mnt/pve/hitachi/dump). Expected archive size is approximately 250 MB.")
|
|
PY
|