backup: 2026-07-11T07:54:39-05:00

This commit is contained in:
jon
2026-07-11 07:54:39 -05:00
parent 8451662d9c
commit 86a26233dc
4 changed files with 466 additions and 97 deletions
+46 -29
View File
@@ -1,22 +1,18 @@
#!/bin/bash
NEXUS_ROOT="$HOME/nexus-core"
SRC="router:/tmp/mnt/Wingdrive2/nexus-core/"
mode="$1"
# Restore NexusOS from Gitea (enderofwings/NexusOS). Clones or pulls the repo,
# rebuilds the memory DB from its SQL dump, then rebuilds the regenerable env
# (venv, frontend deps) and desktop integration (theme, terminal, panel).
#
# restore.sh Pull latest + rebuild.
# restore.sh -c | --claude Dry-run: fetch + show what a restore WOULD apply. No changes.
# Shared exclude list — used by the real restore AND the -c/--claude dry-run, so
# the check accurately previews what a real restore would do.
EXCLUDES=(
--exclude='.git/'
--exclude='Promethean/'
--exclude='models/blobs/'
--exclude='ollama/'
--exclude='interface/web/node_modules/'
--exclude='interface/web/dist/'
--exclude='runtime/'
--exclude='__pycache__/'
--exclude='*.pyc'
)
NEXUS_ROOT="$HOME/nexus-core"
REPO="https://git.enderofwings.com/enderofwings/NexusOS.git"
mode="${1:-}"
DB="$NEXUS_ROOT/synapse/memory/memory.db"
DB_SQL="$NEXUS_ROOT/synapse/memory/memory.db.sql"
detect_requirements() {
if command -v nvidia-smi &>/dev/null || lspci 2>/dev/null | grep -qi nvidia; then
@@ -26,30 +22,49 @@ detect_requirements() {
fi
}
# Check mode (-c|--claude|check): content-level dry-run. Lists exactly what a
# real restore would pull from the router and delete locally — nothing changes
# and the env/theme rebuild is skipped. --checksum compares by content (not
# size/mtime), so only genuine differences show. Meant for deciding whether a
# real restore is actually needed before paying for the rebuild.
# Fresh machine: clone. Existing: work in place.
if [ ! -d "$NEXUS_ROOT/.git" ]; then
echo "No local repo — cloning from Gitea..."
git clone "$REPO" "$NEXUS_ROOT" || { echo "Clone failed."; exit 1; }
fi
cd "$NEXUS_ROOT" || { echo "No $NEXUS_ROOT"; exit 1; }
# Check mode: dry-run. Fetch and show what a real restore would pull, no changes.
if [ "$mode" = "-c" ] || [ "$mode" = "--claude" ] || [ "$mode" = "check" ]; then
echo "Checking restore diff vs router (dry-run, content-level, no changes)..."
rsync -rlni --checksum --delete "${EXCLUDES[@]}" -e ssh "$SRC" "$NEXUS_ROOT/"
echo "Fetching to preview restore (no changes)..."
git fetch origin
echo ""
echo "(dry-run only — nothing changed. Apply with: restore -f)"
echo "Commits a restore would apply:"
git log --oneline ..origin/main 2>/dev/null || echo "(up to date)"
echo ""
git diff --stat ..origin/main 2>/dev/null
echo ""
echo "(dry-run only — nothing changed. Apply with: restore)"
exit 0
fi
if [ "$mode" = "full" ] || [ "$mode" = "-f" ]; then
echo "Restoring full Nexus backup from router..."
else
echo "Restoring Nexus from router..."
echo "Pulling latest from Gitea..."
git pull --ff-only origin main || { echo "Pull failed (diverged? stash/commit local changes)."; exit 1; }
# Rebuild the memory DB from its SQL dump — only if there's no live DB, so we
# never clobber a machine that has newer conversations than the backup.
if [ -f "$DB_SQL" ] && [ ! -f "$DB" ]; then
echo ""
echo "Rebuilding memory DB from dump..."
sqlite3 "$DB" < "$DB_SQL" && echo "Memory DB restored." \
|| echo "Warning: memory DB rebuild failed."
elif [ -f "$DB" ]; then
echo "Live memory DB present — left as-is (dump not applied). Delete it first to restore from backup."
fi
rsync -avz --no-owner --no-group --delete "${EXCLUDES[@]}" -e ssh "$SRC" "$NEXUS_ROOT/"
echo ""
echo "Rebuilding Python environment..."
if [ ! -x "$NEXUS_ROOT/Promethean/bin/pip" ]; then
python3 -m venv "$NEXUS_ROOT/Promethean"
fi
req=$(detect_requirements)
if [ -f "$NEXUS_ROOT/$req" ]; then
"$NEXUS_ROOT/Promethean/bin/pip" install --upgrade pip -q
"$NEXUS_ROOT/Promethean/bin/pip" install -r "$NEXUS_ROOT/$req"
else
echo "Warning: $req not found — skipping pip install."
@@ -58,6 +73,7 @@ fi
echo ""
echo "Rebuilding frontend dependencies..."
cd "$NEXUS_ROOT/interface/web" && npm install
cd "$NEXUS_ROOT"
echo ""
echo "Restoring NexusOS desktop theme..."
@@ -90,3 +106,4 @@ fi
echo ""
echo "Restore complete. Nexus is ready to start."
echo "Note: Ollama models are not in the backup — pull them with \`ollama pull <model>\` as needed."