clone

a personal forge on plain git: static pages, stacked-diff reviews, signed local ci, repo sites and releases

main
forge / test / scenarios / lake-backup.sh
lake-backup.sh 2.3K
1# A backup stages the lake, which nothing can rebuild: a checked copy of2# its catalog (VACUUM INTO, never the live file) and its data files. A3# restore brings it back whole, and the next run there adds nothing twice.4. "$(dirname "$0")/../lib.sh"5user dami6user ana7repo dami/greet8clone dami dami/greet "$T/w/d"9at "$T/w/d" commit "first"10push_as dami "$T/w/d" origin main11clone ana dami/greet "$T/w/a"12at "$T/w/a" commit "idea"13push_as ana "$T/w/a" origin HEAD:ana/idea14build dami/greet15# Enough events that some go to a Parquet file rather than the catalog.16i=017while [ "$i" -lt 30 ]; do18 i=$((i + 1))19 printf '{"t":%s000,"repo":"dami/greet","type":"push","user":"dami","refs":"refs/heads/n%s"}\n' "$((T_NOW + i))" "$i" >>"$FORGE_ROOT/.forge/events.jsonl"20done21ok forge lake22facts="SELECT (SELECT count(*) FROM events) || ' ' || (SELECT count(*) FROM builds) || ' ' || (SELECT count(*) FROM reviews)"23want=$(lq "$facts")24eq "$want" "33 1 2"25ls "$FORGE_ROOT"/.forge/lake/data/main/events/*.parquet >/dev/null 2>&1 || fail "no Parquet file in the lake's data"26ok forge backup --dry-run27st=$FORGE_ROOT/.forge/backup/stage/.forge28exists "$st/lake/catalog.sqlite"29ls "$st"/lake/data/main/events/*.parquet >/dev/null 2>&1 || fail "the lake's data files aren't staged"30missing "$st/lake.lock"31missing "$FORGE_ROOT/.forge/lake.lock"32# A copy, not the live file.33[ "$(ls -i "$st/lake/catalog.sqlite" | awk '{ print $1 }')" != "$(ls -i "$FORGE_ROOT/.forge/lake/catalog.sqlite" | awk '{ print $1 }')" ] || fail "the staged catalog is the live file"34r=$T/restored35ok restore_into "$r" --from "$FORGE_ROOT/.forge/backup/stage"36exists "$r/.forge/lake/catalog.sqlite"37eq "$(FORGE_ROOT=$r FORGE_WWW=$r/.forge/www lq "$facts")" "$want"38# The restored lake reads its own data, not the old forge's.39rm -rf "$FORGE_ROOT/.forge/lake"40eq "$(FORGE_ROOT=$r FORGE_WWW=$r/.forge/www lq "SELECT count(DISTINCT refs) FROM events WHERE refs LIKE 'refs/heads/n%'")" 3041# The restore built every page, so a run there adds those builds and the42# events they wrote, and none of the review lines or events it already had.43ok env FORGE_ROOT="$r" FORGE_WWW="$r/.forge/www" "$FORGE" lake44has "$T_LOG" ', 0 review log lines, 0 ended,'45eq "$(FORGE_ROOT=$r FORGE_WWW=$r/.forge/www lq "SELECT count(*) FROM reviews")" 246eq "$(FORGE_ROOT=$r FORGE_WWW=$r/.forge/www lq "SELECT count(*) FROM events WHERE type = 'push'")" 32