This commit is contained in:
1 parent
415bb3906a
commit
94f1021fd0
5 files changed
+36
-1
No files matched your search
@@ -20,10 +20,25 @@ if [ -z "$DEST_DB_URL" ]; then
|
||||
fi
|
||||
|
||||
DUMP_FILE="${DUMP_FILE:-/tmp/db-sync.dump}"
|
||||
# Comma- and/or space-separated list of tables (or patterns) to skip entirely.
|
||||
# Accepts pg_dump patterns, e.g. "public.logs, schema.audit_*".
|
||||
EXCLUDE_TABLES="${EXCLUDE_TABLES:-}"
|
||||
# Extra safety: force read-only transactions on the source connection.
|
||||
export PGOPTIONS_SOURCE="${PGOPTIONS_SOURCE:--c default_transaction_read_only=on}"
|
||||
|
||||
exclude_args=()
|
||||
if [ -n "$EXCLUDE_TABLES" ]; then
|
||||
# Split on commas and whitespace.
|
||||
read -r -a exclude_items <<< "$(printf '%s' "$EXCLUDE_TABLES" | tr ',' ' ')"
|
||||
for item in "${exclude_items[@]}"; do
|
||||
[ -n "$item" ] && exclude_args+=(--exclude-table="$item")
|
||||
done
|
||||
fi
|
||||
|
||||
log "Starting sync (source -> dest)"
|
||||
if [ "${#exclude_args[@]}" -gt 0 ]; then
|
||||
log "Excluding tables: $EXCLUDE_TABLES"
|
||||
fi
|
||||
log "Dumping source (read-only)..."
|
||||
|
||||
# pg_dump only reads from source. --clean/--if-exists apply DROP statements to DEST on restore.
|
||||
@@ -32,6 +47,7 @@ PGOPTIONS="$PGOPTIONS_SOURCE" pg_dump \
|
||||
--no-owner \
|
||||
--no-acl \
|
||||
--verbose \
|
||||
"${exclude_args[@]}" \
|
||||
--file="$DUMP_FILE" \
|
||||
"$SOURCE_DB_URL"
|
||||
|
||||
|
||||
Reference in new issue
Block a user