8554e7b29c
Behebt 3 von 4 Backup-Luecken (Schicht 1, lokal): - backup.sh sichert jetzt den ECHTEN Zustand als ein Tarball mc2-state-<ts>.tar.gz: mem0 (Chroma+history.db), ~/.hermes (config.yaml, .env, plugins/), llama-swap config. Vorher wurde nur die alte/leere mc2-memory.db gesichert. chmod 600 (enthaelt .env). - restore.sh: --list / --dry-run / [--yes] <datei|latest>; macht VOR dem Zurueckspielen ein Sicherheits-Backup, stoppt/startet Dienste, Health-Check. Live round-trip verifiziert. - mc2-backup.timer/.service: taegliches Backup ~03:30 (vorher gab es KEINE Automatik). - backend/services/backup.py delegiert an backup.sh (eine Quelle der Wahrheit); UI-Button + /api/system/backups zeigen die Tarballs. - docs/BACKUP.md: Backup/Restore-Anleitung. Offen (Schicht 2): Off-Box-Spiegel (Box ist Bare Metal -> PBS-Client oder rsync in LXC). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
48 lines
1.9 KiB
Bash
48 lines
1.9 KiB
Bash
#!/usr/bin/env bash
|
|
# Voll-Zustands-Backup der AI-Box: alles, was NICHT aus Git oder per Re-Download
|
|
# zurückkommt. Erzeugt EIN Tarball mc2-state-<ts>.tar.gz, behält die letzten N.
|
|
# Läuft per systemd-Timer (täglich), manuell, oder über den UI-Snapshot-Button.
|
|
#
|
|
# Inhalt: mem0 (Chroma + history.db) · ~/.hermes (config.yaml, .env, plugins/) ·
|
|
# /etc/llama-swap/config.yaml
|
|
# NICHT enthalten (bewusst): GGUF-Modelle (riesig, neu ladbar), MC2-Code (Git), venvs.
|
|
#
|
|
# ACHTUNG: das Tarball enthält ~/.hermes/.env (Secrets) → chmod 600, nicht in Git.
|
|
set -euo pipefail
|
|
|
|
MODELS_DIR="${MC_MODELS_DIR:-/srv/models}"
|
|
DEST_DIR="$MODELS_DIR/mc2-backups"
|
|
RETAIN="${MC_BACKUP_RETAIN:-14}"
|
|
MEM0_DIR="${MC_MEM0_DIR:-/srv/models/mem0}"
|
|
LSWAP="${MC_CONFIG_PATH:-/etc/llama-swap/config.yaml}"
|
|
HERMES="${HERMES_HOME:-$HOME/.hermes}"
|
|
TS="$(date +%Y%m%d-%H%M%S)"
|
|
|
|
STAGE="$(mktemp -d)"
|
|
trap 'rm -rf "$STAGE"' EXIT
|
|
mkdir -p "$STAGE/mem0" "$STAGE/hermes" "$STAGE/llama-swap"
|
|
|
|
[ -d "$MEM0_DIR" ] && cp -a "$MEM0_DIR/." "$STAGE/mem0/" || true
|
|
[ -f "$HERMES/config.yaml" ] && cp -a "$HERMES/config.yaml" "$STAGE/hermes/" || true
|
|
[ -f "$HERMES/.env" ] && cp -a "$HERMES/.env" "$STAGE/hermes/" || true
|
|
[ -d "$HERMES/plugins" ] && cp -a "$HERMES/plugins" "$STAGE/hermes/plugins" || true
|
|
[ -f "$LSWAP" ] && cp -a "$LSWAP" "$STAGE/llama-swap/" || true
|
|
|
|
cat > "$STAGE/MANIFEST.txt" <<EOF
|
|
mc2-state backup
|
|
created : $TS
|
|
host : $(hostname)
|
|
inhalt : mem0 (chroma + history.db), hermes (config.yaml, .env, plugins/), llama-swap (config.yaml)
|
|
restore : bash ~/mission-control-v2/deploy/restore.sh mc2-state-$TS.tar.gz
|
|
EOF
|
|
|
|
mkdir -p "$DEST_DIR"
|
|
OUT="$DEST_DIR/mc2-state-$TS.tar.gz"
|
|
tar -czf "$OUT" -C "$STAGE" .
|
|
chmod 600 "$OUT" # enthält .env (Secrets)
|
|
|
|
# Retention: nur die letzten N behalten.
|
|
ls -1t "$DEST_DIR"/mc2-state-*.tar.gz 2>/dev/null | tail -n +$((RETAIN + 1)) | xargs -r rm -f
|
|
|
|
echo "OK — Backup: $OUT ($(du -h "$OUT" | cut -f1))"
|