98 lines
3.8 KiB
Bash
Executable File
98 lines
3.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Backup NexusOS via git → Gitea (enderofwings/NexusOS). Replaces the old
|
|
# rsync-to-router backup. Commits the tracked tree (source, config, playbooks,
|
|
# branding, docs) plus a SQL dump of the memory DB, then pushes to the remote —
|
|
# so a fresh clone + restore.sh fully rebuilds the machine.
|
|
#
|
|
# backup.sh Commit changed files + push.
|
|
# backup.sh full | -f Also snapshot live desktop wiring + Claude notes first.
|
|
# backup.sh -c | --claude Dry-run: show what a backup WOULD commit/push. No changes.
|
|
#
|
|
# The regenerable heavies (Promethean venv, ollama binary, models/, node_modules,
|
|
# dist, runtime logs) are intentionally NOT backed up — restore.sh rebuilds them
|
|
# from requirements-*.txt / package-lock.json / `ollama pull`.
|
|
|
|
NEXUS_ROOT="$HOME/nexus-core"
|
|
cd "$NEXUS_ROOT" || { echo "No $NEXUS_ROOT"; exit 1; }
|
|
mode="${1:-}"
|
|
|
|
DB="synapse/memory/memory.db"
|
|
DB_SQL="synapse/memory/memory.db.sql"
|
|
|
|
# Dump the (gitignored, binary, WAL) memory DB to a diff-friendly SQL file so git
|
|
# backs up the assistant's memory + conversation history. sqlite3 reads through
|
|
# the WAL, so the dump includes the latest committed data without a checkpoint.
|
|
dump_db() {
|
|
[ -f "$DB" ] || return 0
|
|
if sqlite3 "$DB" ".dump" > "$DB_SQL" 2>/dev/null; then
|
|
echo "Dumped memory DB → $DB_SQL"
|
|
else
|
|
echo "Warning: could not dump $DB (sqlite3 missing?) — DB not captured"
|
|
fi
|
|
}
|
|
|
|
# full mode: snapshot the LIVE desktop wiring into the repo (reference copy for
|
|
# recovery/diffing; install-theme.sh remains the applier on restore), and copy
|
|
# the Claude memory notes in so git commits their content.
|
|
snapshot_desktop() {
|
|
snap="$NEXUS_ROOT/assets/themes/restore-snapshot"
|
|
mkdir -p "$snap"
|
|
{
|
|
echo "# NexusOS live desktop wiring — snapshot $(date -Is)"
|
|
echo "# Reference only. Restore is done by assets/themes/install-theme.sh"
|
|
for p in /Net/ThemeName /Net/IconThemeName /Gtk/CursorThemeName \
|
|
/Gtk/CursorThemeSize /Gtk/FontName; do
|
|
echo "xsettings $p = $(xfconf-query -c xsettings -p "$p" 2>/dev/null)"
|
|
done
|
|
echo "xfwm4 /general/theme = $(xfconf-query -c xfwm4 -p /general/theme 2>/dev/null)"
|
|
} > "$snap/xfconf.txt" 2>/dev/null || true
|
|
cp -f "$HOME/.config/gtk-3.0/settings.ini" "$snap/gtk-3.0-settings.ini" 2>/dev/null || true
|
|
cp -f "$HOME/.config/gtk-4.0/settings.ini" "$snap/gtk-4.0-settings.ini" 2>/dev/null || true
|
|
cp -f "$HOME/.config/xfce4/panel/genmon-13.rc" \
|
|
"$NEXUS_ROOT/management/panel/genmon-13.rc" 2>/dev/null || true
|
|
|
|
# Copy the Claude memory notes (machine knowledge under ~/.claude) into the
|
|
# repo so they're versioned too. Some aren't Nexus-specific (Fusion 360, etc.).
|
|
notes_src="$HOME/.claude/projects/-home-jon-nexus-core/memory"
|
|
notes_dst="$NEXUS_ROOT/assets/notes"
|
|
mkdir -p "$notes_dst"
|
|
cp -f "$notes_src"/*.md "$notes_dst/" 2>/dev/null || true
|
|
}
|
|
|
|
# Check mode: dry-run. Show what a real backup would commit and push.
|
|
if [ "$mode" = "-c" ] || [ "$mode" = "--claude" ] || [ "$mode" = "check" ]; then
|
|
dump_db
|
|
echo ""
|
|
echo "Files a backup would commit:"
|
|
git status --short
|
|
echo ""
|
|
echo "Local commits not yet pushed:"
|
|
git log --oneline @{u}.. 2>/dev/null || echo "(none / no upstream)"
|
|
echo ""
|
|
echo "(dry-run only — nothing committed or pushed. Apply with: backup)"
|
|
exit 0
|
|
fi
|
|
|
|
if [ "$mode" = "full" ] || [ "$mode" = "-f" ]; then
|
|
snapshot_desktop
|
|
fi
|
|
|
|
dump_db
|
|
git add -A
|
|
if git diff --cached --quiet; then
|
|
echo "No changes to commit."
|
|
else
|
|
git commit -q -m "backup: $(date -Is)"
|
|
echo "Committed backup snapshot."
|
|
fi
|
|
|
|
echo "Pushing to Gitea..."
|
|
if git push origin main; then
|
|
echo "Backup complete."
|
|
else
|
|
echo "Push failed. Set up credentials once with:"
|
|
echo " git config credential.helper store # then push once and enter your Gitea token"
|
|
exit 1
|
|
fi
|