diff --git a/postgres/justfile b/postgres/justfile index d4fed75..e7ee67e 100644 --- a/postgres/justfile +++ b/postgres/justfile @@ -278,9 +278,20 @@ psql *args='': # Dump Postgres database by pg_dump [no-cd] -dump db_name file: +dump db_name file exclude_tables='': + #!/bin/bash + set -euo pipefail + + DUMP_OPTIONS="-Fc" + if [ -n "{{ exclude_tables }}" ]; then + IFS=',' read -ra TABLES <<< "{{ exclude_tables }}" + for table in "${TABLES[@]}"; do + DUMP_OPTIONS="$DUMP_OPTIONS --exclude-table=$table" + done + fi + kubectl exec -i -n ${CNPG_NAMESPACE} postgres-cluster-1 -c postgres -- bash -c \ - "pg_dump -d postgresql://$(just postgres::admin-username):$(just postgres::admin-password)@localhost/{{ db_name }} -Fc > \ + "pg_dump -d postgresql://$(just postgres::admin-username):$(just postgres::admin-password)@localhost/{{ db_name }} $DUMP_OPTIONS > \ /var/lib/postgresql/data/db.dump" kubectl cp -n ${CNPG_NAMESPACE} -c postgres \ postgres-cluster-1:/var/lib/postgresql/data/db.dump {{ file }} @@ -293,6 +304,6 @@ restore db_name file: kubectl cp {{ file }} -n ${CNPG_NAMESPACE} -c postgres \ postgres-cluster-1:/var/lib/postgresql/data/db.dump kubectl exec -i -n ${CNPG_NAMESPACE} postgres-cluster-1 -c postgres -- bash -c \ - "pg_restore --clean --if-exists --no-owner --no-privileges \ + "pg_restore --clean --if-exists \ -d postgresql://$(just postgres::admin-username):$(just postgres::admin-password)@localhost/{{ db_name }} \ /var/lib/postgresql/data/db.dump"