#!/usr/bin/env bash set -euo pipefail REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" LAB_ROOT="${AZEROTHAI_PLAYABLE_ROOT:-$HOME/azerothai-pc-lab}" ACORE_ROOT="$LAB_ROOT/azerothcore" RUNTIME_ENV="$LAB_ROOT/runtime.env" OUT_DIR="${1:-$HOME}" STAMP="$(date +%Y%m%d-%H%M%S)" WORK="$LAB_ROOT/export-$STAMP" ARCHIVE="$OUT_DIR/azerothai-pc-lab-$STAMP.tar.gz" mkdir -p "$WORK/mysql" "$WORK/azerothai" if [[ ! -f "$RUNTIME_ENV" ]]; then echo "Missing $RUNTIME_ENV. This does not look like an initialized PC lab." >&2 exit 2 fi # shellcheck disable=SC1090 source "$RUNTIME_ENV" : "${DOCKER_DB_ROOT_PASSWORD:?Missing database password in runtime.env}" if ! docker inspect ac-database >/dev/null 2>&1; then echo "The AzerothCore database container is not present." >&2 exit 3 fi echo "==> Dumping AzerothCore databases" for db in acore_auth acore_characters acore_world; do docker exec ac-database mysqldump -uroot -p"$DOCKER_DB_ROOT_PASSWORD" --single-transaction --routines --events --triggers "$db" > "$WORK/mysql/$db.sql" done echo "==> Preserving AzerothAI state and runtime configuration" cp "$RUNTIME_ENV" "$WORK/runtime.env" chmod 600 "$WORK/runtime.env" if [[ -d "$REPO_ROOT/.wrangler/state" ]]; then tar -C "$REPO_ROOT" -czf "$WORK/azerothai/wrangler-state.tar.gz" .wrangler/state fi if [[ -d "$LAB_ROOT/etc" ]]; then tar -C "$LAB_ROOT" -czf "$WORK/azerothcore-etc.tar.gz" etc fi cat > "$WORK/MANIFEST.txt" </dev/null || echo unknown) Source commit: $(git -C "$REPO_ROOT" rev-parse HEAD 2>/dev/null || echo unknown) Contains: - acore_auth SQL - acore_characters SQL - acore_world SQL - AzerothAI local D1/SQLite state, when present - AzerothCore generated configuration, when present - runtime.env including bridge/operator/database secrets Treat this archive as sensitive because it contains credentials. EOF echo "==> Creating migration archive" tar -C "$WORK" -czf "$ARCHIVE" . chmod 600 "$ARCHIVE" rm -rf "$WORK" echo echo "Migration export created:" echo " $ARCHIVE" echo echo "Keep this file private. It contains realm data and runtime credentials."