SPB Git

spb/akos

Public
1.2 KB · 12 lines shellscript
1#!/bin/bash2# AKOS restore: scripts/restore.sh <dump-file> [target-db-name] [artifacts.tgz]3# Restores into the target database (default: akos_restore_test — never the live DB unless you pass it explicitly).4set -euo pipefail5export PATH=/opt/homebrew/opt/postgresql@17/bin:/opt/homebrew/bin:/usr/bin:/bin6DUMP="${1:?dump file}"; DB="${2:-akos_restore_test}"; ART="${3:-}"7if [ -f "${DUMP%.dump}.sha256" ]; then (cd "$(dirname "$DUMP")" && shasum -a 256 -c "$(basename "${DUMP%.dump}.sha256")" >/dev/null) && echo "checksum ok"; fi8psql -d postgres -tAc "SELECT 1 FROM pg_database WHERE datname='$DB'" | grep -q 1 || psql -d postgres -qc "CREATE DATABASE $DB OWNER akos"9pg_restore --clean --if-exists --no-owner -d "$DB" "$DUMP"10echo "restored $DUMP into $DB: $(psql -d "$DB" -tAc 'select count(*) from executions') executions, $(psql -d "$DB" -tAc 'select count(*) from knowledge_packages') packages, $(psql -d "$DB" -tAc 'select count(*) from audit_events') audit events"11if [ -n "$ART" ]; then DEST="${AKOS_RESTORE_DATA:-/tmp/akos-restore-data}"; mkdir -p "$DEST"; tar -C "$DEST" -xzf "$ART"; echo "artifacts extracted to $DEST/artifacts ($(find "$DEST/artifacts" -type f | wc -l | tr -d ' ') files)"; fi12
Files · da58f809c01c422e65c786b05d6ffa3079c9feba
Menu

Theme