Files
Learn_System/backend/scripts/backup.sh
T
Maxim Dolgolyov be4d43105e LearnSpace: full-stack educational whiteboard platform
Node.js/Express backend + vanilla JS frontend.
Features: real-time collaborative whiteboard (SSE), multi-page support,
LaTeX formulas, shapes/connectors, coordinate systems, number lines,
compass, zoom/pan, Catmull-Rom pencil smoothing, ruler/protractor with
rotation & resize controls, minimap navigation overlay, auto-measurements,
multi-page thumbnails sidebar, PNG export, page templates.
Student/teacher workflows: classes, assignments, library, dashboard.
Mobile responsive. SQLite (better-sqlite3).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-12 10:10:37 +03:00

50 lines
1.8 KiB
Bash

#!/bin/sh
# ── LearnSpace SQLite backup ──────────────────────────────────────────────
# Uses VACUUM INTO for a safe, consistent snapshot (no WAL/SHM issues).
# Usage:
# ./backup.sh # default paths
# ./backup.sh /path/to/db /path/to/backups
# KEEP=14 ./backup.sh # keep last 14 backups (default: 7)
# ─────────────────────────────────────────────────────────────────────────
set -e
DB_PATH="${1:-${DB_PATH:-$(dirname "$0")/../data/learnspace.db}}"
BACKUP_DIR="${2:-${BACKUP_DIR:-$(dirname "$0")/../../backups}}"
KEEP="${KEEP:-7}"
if [ ! -f "$DB_PATH" ]; then
echo "[backup] ERROR: database not found at $DB_PATH" >&2
exit 1
fi
mkdir -p "$BACKUP_DIR"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="$BACKUP_DIR/learnspace_${TIMESTAMP}.db"
echo "[backup] Creating snapshot: $BACKUP_FILE"
sqlite3 "$DB_PATH" "VACUUM INTO '$BACKUP_FILE';"
# Verify backup is not empty
SIZE=$(wc -c < "$BACKUP_FILE" | tr -d ' ')
if [ "$SIZE" -lt 1024 ]; then
echo "[backup] ERROR: backup file is suspiciously small (${SIZE} bytes)" >&2
rm -f "$BACKUP_FILE"
exit 1
fi
echo "[backup] OK — $(echo "scale=1; $SIZE / 1048576" | bc 2>/dev/null || echo "$SIZE bytes")"
# Rotate: keep only the last $KEEP backups
COUNT=$(ls -1 "$BACKUP_DIR"/learnspace_*.db 2>/dev/null | wc -l)
if [ "$COUNT" -gt "$KEEP" ]; then
REMOVE=$((COUNT - KEEP))
ls -1t "$BACKUP_DIR"/learnspace_*.db | tail -n "$REMOVE" | while read -r f; do
echo "[backup] Removing old: $(basename "$f")"
rm -f "$f"
done
fi
echo "[backup] Done. Backups retained: $KEEP"