feat(db): add database backup/restore tooling
- tooling/db-backup: copies shared settledreach.db to docs/backups/ for git tracking (main branch only) - tooling/db-install: restores from backup for new clones - make db-backup / make db-install Makefile targets - worktree-update skill runs make db-backup after merges on main Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Executable
+23
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copy the shared database into git-tracked docs/backups/ for disaster recovery.
|
||||
# Only runs on the main branch — called via `make db-backup`.
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
WORKTREE_ROOT="$(dirname "$SCRIPT_DIR")"
|
||||
DB_PATH="$(dirname "$WORKTREE_ROOT")/settledreach.db"
|
||||
BACKUP_PATH="$WORKTREE_ROOT/docs/backups/settledreach.db.backup"
|
||||
|
||||
branch="$(git -C "$WORKTREE_ROOT" branch --show-current)"
|
||||
if [ "$branch" != "main" ]; then
|
||||
echo "error: db-backup only runs on the main branch (currently on '$branch')" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f "$DB_PATH" ]; then
|
||||
echo "error: shared database not found at $DB_PATH" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cp "$DB_PATH" "$BACKUP_PATH"
|
||||
echo "ok: backed up $(du -h "$BACKUP_PATH" | cut -f1) to docs/backups/settledreach.db.backup"
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
# Restore the shared database from the git-tracked backup.
|
||||
# Use after cloning or when the shared database is missing.
|
||||
# Called via `make db-install`.
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
WORKTREE_ROOT="$(dirname "$SCRIPT_DIR")"
|
||||
DB_PATH="$(dirname "$WORKTREE_ROOT")/settledreach.db"
|
||||
BACKUP_PATH="$WORKTREE_ROOT/docs/backups/settledreach.db.backup"
|
||||
|
||||
if [ -f "$DB_PATH" ]; then
|
||||
echo "error: shared database already exists at $DB_PATH" >&2
|
||||
echo " delete it first if you want to restore from backup" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f "$BACKUP_PATH" ]; then
|
||||
echo "error: backup not found at $BACKUP_PATH" >&2
|
||||
echo " run 'make db-backup' on the main branch first" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cp "$BACKUP_PATH" "$DB_PATH"
|
||||
echo "ok: restored $(du -h "$DB_PATH" | cut -f1) to $DB_PATH"
|
||||
Reference in New Issue
Block a user