forked from sagnik/Project_Velocity
fix: Applied fix for name, the oracle team sharing, sentinel client list visibility
This commit is contained in:
122
scripts/export_velocity_local_bundle.sh
Normal file
122
scripts/export_velocity_local_bundle.sh
Normal file
@@ -0,0 +1,122 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Run this on the Linux origin host that currently serves velocity.desineuron.in.
|
||||
# It exports a local-development bundle containing:
|
||||
# - backend env snapshot (non-shell format)
|
||||
# - PostgreSQL custom-format dump
|
||||
# - app build metadata
|
||||
# - optional asset snapshot manifest
|
||||
#
|
||||
# Output:
|
||||
# /tmp/velocity-local-bundle-YYYYmmdd-HHMMSS.tar.gz
|
||||
|
||||
REPO_ROOT="${REPO_ROOT:-/opt/desineuron-velocity-site/repo}"
|
||||
BACKEND_ENV_PATH="${BACKEND_ENV_PATH:-$REPO_ROOT/backend/.env}"
|
||||
OUTPUT_ROOT="${OUTPUT_ROOT:-/tmp}"
|
||||
DB_CONTAINER_NAME="${DB_CONTAINER_NAME:-desineuron-ops-db}"
|
||||
STAMP="$(date +%Y%m%d-%H%M%S)"
|
||||
WORKDIR="$OUTPUT_ROOT/velocity-local-bundle-$STAMP"
|
||||
ARCHIVE="$OUTPUT_ROOT/velocity-local-bundle-$STAMP.tar.gz"
|
||||
|
||||
if [[ ! -f "$BACKEND_ENV_PATH" ]]; then
|
||||
echo "Missing backend env file: $BACKEND_ENV_PATH" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$WORKDIR"
|
||||
|
||||
cp "$BACKEND_ENV_PATH" "$WORKDIR/backend.env.raw"
|
||||
|
||||
python3 - "$WORKDIR/backend.env.raw" "$WORKDIR/backend.env.export" <<'PY'
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
src = pathlib.Path(sys.argv[1])
|
||||
dst = pathlib.Path(sys.argv[2])
|
||||
|
||||
allowed = {
|
||||
"VELOCITY_DB_HOST",
|
||||
"VELOCITY_DB_PORT",
|
||||
"VELOCITY_DB_NAME",
|
||||
"VELOCITY_DB_USER",
|
||||
"VELOCITY_DB_PASSWORD",
|
||||
"DATABASE_URL",
|
||||
"CORS_ORIGINS",
|
||||
"VELOCITY_ASSET_DIR",
|
||||
"JWT_SECRET_KEY",
|
||||
"JWT_ALGORITHM",
|
||||
"JWT_EXP_MINUTES",
|
||||
}
|
||||
|
||||
lines = []
|
||||
for raw_line in src.read_text(encoding="utf-8").splitlines():
|
||||
line = raw_line.strip()
|
||||
if not line or line.startswith("#") or "=" not in line:
|
||||
continue
|
||||
key, value = line.split("=", 1)
|
||||
key = key.strip()
|
||||
if key in allowed:
|
||||
lines.append(f"{key}={value.strip()}")
|
||||
|
||||
dst.write_text("\n".join(lines) + "\n", encoding="utf-8")
|
||||
PY
|
||||
|
||||
set -a
|
||||
source "$BACKEND_ENV_PATH"
|
||||
set +a
|
||||
|
||||
dump_with_local_pg_dump() {
|
||||
PGPASSWORD="${VELOCITY_DB_PASSWORD}" pg_dump \
|
||||
-h "${VELOCITY_DB_HOST}" \
|
||||
-p "${VELOCITY_DB_PORT}" \
|
||||
-U "${VELOCITY_DB_USER}" \
|
||||
-d "${VELOCITY_DB_NAME}" \
|
||||
-Fc \
|
||||
-f "$WORKDIR/velocity.dump"
|
||||
}
|
||||
|
||||
dump_with_docker_exec() {
|
||||
if ! command -v docker >/dev/null 2>&1; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
sudo -n docker exec \
|
||||
-e PGPASSWORD="${VELOCITY_DB_PASSWORD}" \
|
||||
"$DB_CONTAINER_NAME" \
|
||||
pg_dump \
|
||||
-U "${VELOCITY_DB_USER}" \
|
||||
-d "${VELOCITY_DB_NAME}" \
|
||||
-Fc \
|
||||
> "$WORKDIR/velocity.dump"
|
||||
}
|
||||
|
||||
if command -v pg_dump >/dev/null 2>&1; then
|
||||
dump_with_local_pg_dump
|
||||
elif dump_with_docker_exec; then
|
||||
:
|
||||
else
|
||||
echo "Neither host pg_dump nor docker-exec pg_dump is available." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cat > "$WORKDIR/README.txt" <<EOF
|
||||
Velocity local bundle
|
||||
Created: $(date --iso-8601=seconds)
|
||||
Repo root: $REPO_ROOT
|
||||
Bundle contents:
|
||||
- backend.env.export
|
||||
- velocity.dump
|
||||
- restore.instructions.txt
|
||||
EOF
|
||||
|
||||
cat > "$WORKDIR/restore.instructions.txt" <<EOF
|
||||
1. Copy this archive to the Windows development machine.
|
||||
2. Extract it under Project_Velocity/.local-dev/source-bundles/<bundle-name>.
|
||||
3. Run scripts/import_velocity_local_bundle.ps1 from the repo root.
|
||||
EOF
|
||||
|
||||
tar -C "$OUTPUT_ROOT" -czf "$ARCHIVE" "$(basename "$WORKDIR")"
|
||||
rm -rf "$WORKDIR"
|
||||
|
||||
echo "Created bundle: $ARCHIVE"
|
||||
Reference in New Issue
Block a user