Files
felhom.eu/documentation/audits/night-2026-09-24/tools/liveA1.py
T
2026-09-24 13:05:29 +02:00

45 lines
2.6 KiB
Python

#!/usr/bin/env python3
"""A1 live on 9202 (v0.269.0) — decision 26: nextcloud (file app) with a fresh second copy, files changed through
the front door, a failing update whose undo copy is cut off (→ HOLD), then the second copy's „Teljes
visszaállítás" = the WHOLE restore. Read back: the account, every file, the counts."""
import html as H, json, re, sys, time
sys.path.insert(0, ".")
import walk as w, fixtures as fx, ncfiles as nf
F, SUB, APP = fx.Nextcloud(), "cloud-a1", "nextcloud"
CAT = f"{w.DRILL}/templates/{APP}"
S = json.load(open(f"{w.SC}/a1-secret-state.json"))
A, files = S["A"], S["files"]
out = {"controller": w.guest("cat /etc/felhom-controller-image").strip()}
w.login()
def drill(edit, msg):
import fcntl
with open(f"{w.SC}/drill.lock", "w") as lk:
fcntl.flock(lk, fcntl.LOCK_EX)
w.sh(["git", "-C", w.DRILL, "pull", "-q", "--rebase", "origin", "main"], timeout=120)
edit()
w.sh(["git", "-C", w.DRILL, "commit", "-qam", "NIGHT-A1 " + msg])
w.sh(["git", "-C", w.DRILL, "push", "-q", "origin", "main"], timeout=120)
w.say("drill: " + msg)
HEAD = open(f"{CAT}/docker-compose.yml").read()
FY = open(f"{CAT}/.felhom.yml").read()
names = list(files)
# (a) a fresh backup + second copy: an update whose tag does not exist
drill(lambda: open(f"{CAT}/docker-compose.yml", "w").write(HEAD.replace("nextcloud:34.0.4-apache", "nextcloud:34.0.98-notag")), "notag (backing-up + Tier 2, pull fails)")
w.sync_rescan(APP, "nextcloud:34.0.98-notag", tries=60)
# make the copy fresh-older than backup_max_age? the existing unit is < 24 h old -> force the backup by nothing: the
# precondition may lean on the existing copy. So record which copy it used.
out["press_a"] = w.press_update(APP)
out["log_a"] = w.guest("docker logs --since 5m felhom-controller 2>&1 | grep -E 'nextcloud' | grep -iE 'Tier 2|precondition|same-disk|backup' | tail -8")
w.say("log (a):\n" + out["log_a"])
drill(lambda: open(f"{CAT}/docker-compose.yml", "w").write(HEAD), "back to 34.0.4")
out["mirror"] = w.guest("""for b in $(find /mnt/sys_drive /mnt/felhom-drives -maxdepth 7 -type d -path '*backups/secondary/nextcloud' 2>/dev/null); do echo "== $b"; ls $b; find $b -name 'felhom-seed-*' | sed 's|.*/||'; done""")
w.say("mirrors:\n" + out["mirror"])
out["record"] = w.guest("python3 -c \"import json;d=json.load(open('/var/lib/docker/volumes/felhom-controller-data/_data/data/settings.json'));print(json.dumps(d['app_backup']['nextcloud']['cross_drive']))\"")
w.say("Tier-2 record: " + out["record"])
json.dump(out, open("../A1/11-copy.json", "w"), indent=2, default=str)
open("../A1/11-copy.log", "w").write("\n".join(w.LOG) + "\n")