Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
99 lines
4.3 KiB
Bash
Executable File
99 lines
4.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# copy.sh: dump one Menivor database and restore it into an EMPTY one (MG9).
|
|
#
|
|
# copy.sh --source <endpoint> --target <endpoint> --work <dir> [--allow-major-upgrade]
|
|
#
|
|
# Steps:
|
|
# 1. The target must have no user tables (a restore never merges into data).
|
|
# 2. Postgres majors: the target must match the source (--allow-major-upgrade
|
|
# permits a newer target, e.g. box 16 to Neon 17).
|
|
# 3. pg_dump -Fc --no-owner --no-acl from the source into <dir>/menivor.dump,
|
|
# with a sha256 next to it. Custom format, so it is also a restore point.
|
|
# 4. The archive's table of contents minus "COMMENT - EXTENSION" entries (a
|
|
# managed role such as Neon's owner may not comment on extensions it does
|
|
# not own), then pg_restore --single-transaction --exit-on-error: the target
|
|
# gets everything or nothing.
|
|
# Prints "COPY OK dump_bytes=<n> dump_s=<n> restore_s=<n>" on success.
|
|
#
|
|
# Endpoints: see lib.sh. The dump holds customer data; <dir> is created 0700.
|
|
set -Eeuo pipefail
|
|
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
# shellcheck source=lib.sh
|
|
. "$HERE/lib.sh"
|
|
|
|
usage() { sed -n '2,19p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; exit 2; }
|
|
|
|
SRC="" TGT="" WORKDIR="" UPGRADE=0
|
|
while (($#)); do
|
|
case "$1" in
|
|
--source) SRC="$2"; shift ;;
|
|
--target) TGT="$2"; shift ;;
|
|
--work) WORKDIR="$2"; shift ;;
|
|
--allow-major-upgrade) UPGRADE=1 ;;
|
|
-h | --help) usage ;;
|
|
*) echo "unknown argument: $1" >&2; usage ;;
|
|
esac
|
|
shift
|
|
done
|
|
[[ -n "$SRC" && -n "$TGT" && -n "$WORKDIR" ]] || usage
|
|
[[ "$SRC" != "$TGT" ]] || ncut_die "source and target are the same endpoint"
|
|
ncut_endpoint_check "$SRC"
|
|
ncut_endpoint_check "$TGT"
|
|
install -d -m 700 "$WORKDIR"
|
|
WORKDIR="$(cd "$WORKDIR" && pwd)"
|
|
|
|
# --- 1 and 2: target empty, majors ---------------------------------------------
|
|
existing="$(ncut_user_tables "$TGT" | grep -c . || true)"
|
|
[[ "$existing" == 0 ]] || ncut_die "target already has $existing user tables; restore only into an empty database"
|
|
src_major="$(ncut_server_major "$SRC")"
|
|
tgt_major="$(ncut_server_major "$TGT")"
|
|
if [[ "$src_major" != "$tgt_major" ]]; then
|
|
if ! ((UPGRADE && tgt_major > src_major)); then
|
|
ncut_die "Postgres major differs: source $src_major, target $tgt_major (create the Neon project on $src_major, or pass --allow-major-upgrade for a newer target)"
|
|
fi
|
|
fi
|
|
ncut_log "source Postgres $src_major, target Postgres $tgt_major, target empty"
|
|
|
|
# --- 3: dump -------------------------------------------------------------------
|
|
DUMP="$WORKDIR/menivor.dump"
|
|
t0=$SECONDS
|
|
ncut_log "dumping $SRC"
|
|
# pg_dump must be at least the source's major (only matters for an env: source).
|
|
NCUT_PG_MAJOR="$src_major"
|
|
ncut_pg "$SRC" pg_dump -Fc --no-owner --no-acl >"$DUMP.tmp"
|
|
mv -f "$DUMP.tmp" "$DUMP"
|
|
chmod 600 "$DUMP"
|
|
dump_s=$((SECONDS - t0))
|
|
dump_bytes="$(wc -c <"$DUMP" | tr -d ' ')"
|
|
((dump_bytes > 0)) || ncut_die "empty dump"
|
|
(cd "$WORKDIR" && { sha256sum menivor.dump 2>/dev/null || shasum -a 256 menivor.dump; } >menivor.dump.sha256)
|
|
ncut_log "dump: $dump_bytes bytes in ${dump_s}s"
|
|
|
|
# --- 4: filtered restore -------------------------------------------------------
|
|
# Listing reads only the archive, so any pg_restore of the target's major will do.
|
|
NCUT_PG_MAJOR="$tgt_major"
|
|
docker run --rm -i "postgres:${tgt_major}-alpine" pg_restore -l <"$DUMP" >"$WORKDIR/restore.list"
|
|
grep -v ' COMMENT - EXTENSION ' "$WORKDIR/restore.list" >"$WORKDIR/restore.use.list" || true
|
|
dropped=$(($(wc -l <"$WORKDIR/restore.list") - $(wc -l <"$WORKDIR/restore.use.list")))
|
|
ncut_log "restore list: $(grep -c ';' "$WORKDIR/restore.use.list" || true) entries ($dropped extension comment(s) left out)"
|
|
|
|
t0=$SECONDS
|
|
ncut_log "restoring into $TGT"
|
|
case "$TGT" in
|
|
env:*)
|
|
NCUT_MOUNT="$WORKDIR" ncut_pg "$TGT" pg_restore --no-owner --no-acl --single-transaction \
|
|
--exit-on-error -L /work/restore.use.list <"$DUMP"
|
|
;;
|
|
container:*)
|
|
name="${TGT#container:}"; name="${name%%/*}"
|
|
inbox="/tmp/ncut-restore-$$.list"
|
|
docker cp "$WORKDIR/restore.use.list" "$name:$inbox"
|
|
ncut_pg "$TGT" pg_restore --no-owner --no-acl --single-transaction \
|
|
--exit-on-error -L "$inbox" <"$DUMP" || { docker exec "$name" rm -f "$inbox"; exit 1; }
|
|
docker exec "$name" rm -f "$inbox"
|
|
;;
|
|
esac
|
|
restore_s=$((SECONDS - t0))
|
|
ncut_log "restore: ${restore_s}s"
|
|
echo "COPY OK dump_bytes=$dump_bytes dump_s=$dump_s restore_s=$restore_s src_major=$src_major tgt_major=$tgt_major"
|