#!/usr/bin/env python3 """A1 spike: what does nextcloud's Tier-2 mirror hold, file by file, and what would a whole restore need? nextcloud installed from the drill (= live head), a user + 3 files through WebDAV, then an update whose tag does not exist: its backing-up leg runs (unit + Tier 2), the pull fails, nothing moves.""" import 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}" out = {} w.login() w.sync_rescan() out["deployed"] = w.deploy(APP, SUB) A = F.seed(w, SUB, w.say) files = nf.seed_files(w, SUB, A, 3, w.say) out["files_seeded"] = len(files) 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) orig = open(f"{CAT}/docker-compose.yml").read() drill(lambda: open(f"{CAT}/docker-compose.yml", "w").write(orig.replace("nextcloud:34.0.4-apache", "nextcloud:34.0.99-notag")), "nextcloud 34.0.99-notag (backing-up runs, pull fails)") w.sync_rescan(APP, "nextcloud:34.0.99-notag", tries=60) out["press"] = w.press_update(APP) drill(lambda: open(f"{CAT}/docker-compose.yml", "w").write(orig), "nextcloud back to 34.0.4") w.sync_rescan() cfg = w.guest("python3 - <<'PY'\nimport json\nd=json.load(open('/var/lib/docker/volumes/felhom-controller-data/_data/data/settings.json'))\nprint(json.dumps((d.get('cross_drive') or d.get('crossdrive') or {}).get('nextcloud'),indent=1))\nPY") out["tier2_record"] = cfg w.say("Tier-2 record:\n" + cfg) lay = w.guest("""for b in /mnt/sys_drive/felhom-data/backups/secondary/nextcloud /mnt/felhom-drives/scratch_hdd/backups/secondary/nextcloud; do [ -d $b ] || continue; echo "== $b"; ls -la $b; du -sh $b/* 2>/dev/null; find $b -maxdepth 4 -type d | head -30; done echo "== live userdata"; ls -la /mnt/felhom-drives/scratch_hdd/userdata/nextcloud 2>&1 | head; find /mnt/felhom-drives/scratch_hdd/userdata/nextcloud -name 'felhom-seed-*' -printf '%p %s %TY-%Tm-%Td %TH:%TM %u:%g %m\\n' 2>/dev/null echo "== mirror copies of the seeds"; find /mnt/sys_drive/felhom-data/backups/secondary/nextcloud /mnt/felhom-drives/scratch_hdd/backups/secondary/nextcloud -name 'felhom-seed-*' -printf '%p %s %TY-%Tm-%Td %TH:%TM %u:%g %m\\n' 2>/dev/null""") out["layout"] = lay w.say("layout:\n" + lay) json.dump({"A": {"uid": A["uid"]}, "files": list(files)}, open("../A1/spike-state.json", "w"), indent=2) json.dump(out, open("../A1/00-spike.json", "w"), indent=2, ensure_ascii=False, default=str) open("../A1/00-spike.log", "w").write("\n".join(w.LOG) + "\n") json.dump({"A": A, "files": files}, open(f"{w.SC}/a1-secret-state.json", "w"))