80 lines
2.3 KiB
Python
80 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Stelle das crs326-core Backup vom Cutover-Stand wieder her.
|
|
|
|
Creds aus ~/.claude.json (mikromcp-env, CRS326_CORE_*).
|
|
Backup-Datei wird per SCP hochgeladen und /system backup load ausgefuehrt.
|
|
"""
|
|
import json
|
|
import pathlib
|
|
import subprocess
|
|
import sys
|
|
|
|
CORE_IP = "192.168.88.1"
|
|
BACKUP = "crs326-core-pre-cutover-20260806-073712.backup"
|
|
CLAUDE_JSON = pathlib.Path.home() / ".claude.json"
|
|
OUT_DIR = pathlib.Path(__file__).resolve().parent
|
|
|
|
|
|
def load_core_creds():
|
|
cfg = json.loads(CLAUDE_JSON.read_text())
|
|
env = cfg.get("mcpServers", {}).get("mikromcp", {}).get("env", {})
|
|
user = env.get("CRS326_CORE_USER") or env.get("ROUTER_USER")
|
|
pw = env.get("CRS326_CORE_PASS") or env.get("ROUTER_PASS")
|
|
if not user or not pw:
|
|
raise SystemExit("CRS326_CORE_USER/PASS nicht in ~/.claude.json mikromcp.env gefunden")
|
|
return user, pw
|
|
|
|
|
|
def ssh_cmd(user, pw, remote_command):
|
|
return [
|
|
"sshpass", "-p", pw,
|
|
"ssh",
|
|
"-o", "StrictHostKeyChecking=no",
|
|
"-o", "UserKnownHostsFile=/dev/null",
|
|
"-o", "PubkeyAuthentication=no",
|
|
f"{user}@{CORE_IP}",
|
|
remote_command,
|
|
]
|
|
|
|
|
|
def scp_cmd(user, pw, local_file, remote_file):
|
|
return [
|
|
"sshpass", "-p", pw,
|
|
"scp",
|
|
"-o", "StrictHostKeyChecking=no",
|
|
"-o", "UserKnownHostsFile=/dev/null",
|
|
"-o", "PubkeyAuthentication=no",
|
|
str(local_file),
|
|
f"{user}@{CORE_IP}:{remote_file}",
|
|
]
|
|
|
|
|
|
def run_silent(cmd, pw):
|
|
r = subprocess.run(cmd, capture_output=True, text=True)
|
|
if r.returncode != 0:
|
|
out = (r.stdout + r.stderr).replace(pw, "***")
|
|
raise SystemExit(f"Befehl fehlgeschlagen (rc={r.returncode}):\n{out}")
|
|
return r
|
|
|
|
|
|
def main():
|
|
local_backup = OUT_DIR / BACKUP
|
|
if not local_backup.exists():
|
|
raise SystemExit(f"{local_backup} fehlt")
|
|
|
|
user, pw = load_core_creds()
|
|
|
|
print(f"crs326-core Restore via SSH {user}@{CORE_IP}")
|
|
print(f" Lade {BACKUP} hoch ...")
|
|
run_silent(scp_cmd(user, pw, local_backup, BACKUP), pw)
|
|
|
|
print(f" Spiele Backup zurueck ...")
|
|
run_silent(ssh_cmd(user, pw, f'/system backup load name="{BACKUP}" password=""'), pw)
|
|
|
|
print(" Backup geladen, Router rebootet.")
|
|
print(" Warte auf Wiederverbindung an 10.40.41.211 ...")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|