Eu quero copiar a DB (para uma nova) onde eu excluo todos os dados nas tuas
gorfs tabelas (gorfs.inodes, gorfs.inode_segments)

Podem verificar se fiz certo?

Obrigado


#!/bin/bash -eu


declare -r -x PATH='/usr/local/bin:/usr/bin:/bin';
declare -r ORIGINAL_IFS="${IFS}";

declare -r DB_HOST_SRC='127.0.0.1';
declare -r -i DB_PORT_SRC=15432;
declare -r DB_USER_SRC='db_dba';
declare -r DB_NAME_SRC='db_live';

declare -r DB_HOST_DST='localhost';
declare -r -i DB_PORT_DST=5432;
declare -r DB_USER_DST='db_dba';

declare -r SCHEMA_ONLY_TABLES='gorfs.inodes:gorfs.inode_segments'; #
colon-separated

declare -r HTTP_FILE='https://shed.db.com/geoop_vagrant.psql.bz2';
declare -r HTTP_USER='user_janitor';
declare -r HTTP_PASSWORD='XXXXXXX';

declare DUMP_MODE='no_gorfs'; # can be full, no_gorfs or shrunk. Parameters
override this
declare -a PSQL_SCHEMA_ONLY_ARGS='';


declare NEW_DB_NAME='newdb_vanilla';


function abort_all() {
psql \
--host="${DB_HOST_DST}" \
--port=${DB_PORT_DST} \
--username="${DB_USER_DST}" \
'postgres' \
-c "DROP DATABASE \""${NEW_DB_NAME}\"";" \
;
exit 4;
}


if [ ${#} -gt 0 ]; then
if [[ "${1}" =~ ^((full)|(nogorfs)|(shrunk))$ ]]; then
DUMP_MODE="${1}";
else
printf 'Usage:\n' 1>&2;
printf '\t%s: {full | nogorfs | shrunk}\n' "${0}" 1>&2;
exit 2;
fi;
fi;

# we create the new database name and the database itself
NEW_DB_NAME="${NEW_DB_NAME}_${DUMP_MODE}_$(date --utc
+'%Y%m%d%H%M%S')_${$}";

trap abort_all 'HUP' 'INT' 'TERM' 'QUIT';

psql \
--host="${DB_HOST_DST}" \
--port=${DB_PORT_DST} \
--username="${DB_USER_DST}" \
'postgres' \
-c "CREATE DATABASE \""${NEW_DB_NAME}\"";" \
|| exit 3;

(
printf "SET synchronous_commit TO 'off';\n"
case "${DUMP_MODE}" in

('full' | 'nogorfs')

if [ "${DUMP_MODE}" = 'nogorfs' ] && [ -n "${SCHEMA_ONLY_TABLES}" ]; then
PSQL_SCHEMA_ONLY_ARGS="--exclude-table-data=${SCHEMA_ONLY_TABLES//:/
--exclude-table-data=}";
fi;

printf 'BEGIN TRANSACTION;\n' &&
pg_dump \
--host="${DB_HOST_SRC}" \
--port=${DB_PORT_SRC} \
--username="${DB_USER_SRC}" \
${PSQL_SCHEMA_ONLY_ARGS} \
"${DB_NAME_SRC}" \
&&
printf 'COMMIT TRANSACTION;\n';

#)\ | /usr/pgsql-9.2/bin/psql -a -h localhost -U db_dba db_fresh
;;

('shrunk')
wget -O - -q --user="${HTTP_USER}" --password="${HTTP_PASSWORD}"
"${HTTP_FILE}" | bzip2 -c -d;
;;

esac;
) | psql \
--set='ON_ERROR_STOP=1' \
--host="${DB_HOST_DST}" \
--port=${DB_PORT_DST} \
--username="${DB_USER_DST}" \
${NEW_DB_NAME} \
|| psql \
--host="${DB_HOST_DST}" \
--port=${DB_PORT_DST} \
--username="${DB_USER_DST}" \
'postgres' \
-c "DROP DATABASE \""${NEW_DB_NAME}\"";" \
; # the database is dropped if something fails

printf 'db_name: %s\n' "${NEW_DB_NAME}";
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Responder a