Files
ra-h-os/scripts/database/sqlite-restore.sh
T
“BeeRad” 733d1c3407 Initial commit: RA-H Open Source Edition
Local-first knowledge management system with BYO API keys.

Features:
- 3-panel UI (Nodes | Focus | Helpers)
- SQLite + sqlite-vec for vector search
- Agent system (Easy/Hard mode orchestrators)
- Content extraction (YouTube, PDF, web)
- Integrate workflow for connection discovery
- Dimension system with auto-assignment

Tech stack:
- Next.js 15 + TypeScript + Tailwind CSS
- Anthropic (Claude) + OpenAI (GPT) via Vercel AI SDK

Setup:
  npm install && npm rebuild better-sqlite3
  scripts/dev/bootstrap-local.sh
  npm run dev

MIT License
2025-12-15 16:14:28 +11:00

63 lines
1.6 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
# Restore RA-H SQLite database from a backup snapshot
if [ $# -lt 1 ]; then
echo "Usage: $0 <backup.sqlite>" >&2
exit 1
fi
SRC="$1"
if [ ! -f "$SRC" ]; then
echo "Backup file not found: $SRC" >&2
exit 1
fi
# Resolve target DB path in this order:
# 1) $SQLITE_DB_PATH (env)
# 2) ./.env.local → SQLITE_DB_PATH
# 3) Default dev path under ~/Library
DB_PATH=${SQLITE_DB_PATH:-}
if [ -z "${DB_PATH}" ] && [ -f ".env.local" ]; then
DB_PATH=$(grep -E '^SQLITE_DB_PATH=' .env.local | sed 's/^SQLITE_DB_PATH=//' | sed 's/^"\(.*\)"$/\1/') || true
fi
if [ -z "${DB_PATH}" ]; then
DB_PATH="$HOME/Library/Application Support/RA-H/db/rah.sqlite"
fi
DB_DIR="$(dirname "$DB_PATH")"
mkdir -p "$DB_DIR"
echo "Source backup: $SRC"
echo "Target DB: $DB_PATH"
echo "Verifying backup integrity before restore..."
ICHECK=$(sqlite3 "$SRC" "PRAGMA integrity_check;")
echo " $ICHECK"
if [ "$ICHECK" != "ok" ]; then
echo "❌ Backup integrity check failed — aborting restore" >&2
exit 2
fi
TS=$(date +"%Y%m%d_%H%M%S")
SAFE_COPY="$DB_DIR/rah_pre_restore_${TS}.sqlite"
echo "Creating safety copy: $SAFE_COPY"
cp -f "$DB_PATH" "$SAFE_COPY" 2>/dev/null || true
echo "Restoring backup..."
cp -f "$SRC" "$DB_PATH"
echo "Integrity check on restored DB..."
RCHECK=$(sqlite3 "$DB_PATH" "PRAGMA integrity_check;")
echo " $RCHECK"
if [ "$RCHECK" != "ok" ]; then
echo "❌ Restored DB integrity check failed" >&2
exit 3
fi
echo "Restored counts:"
sqlite3 "$DB_PATH" "SELECT 'nodes',COUNT(*) FROM nodes UNION ALL SELECT 'edges',COUNT(*) FROM edges UNION ALL SELECT 'chunks',COUNT(*) FROM chunks;" | sed 's/^/ /'
echo "✅ Restore complete."