Yedidyah Bar David has uploaded a new change for review. Change subject: pg_cmd ......................................................................
pg_cmd Change-Id: I168c89a988854f2d912e31fa9a02b89c9d924dbb Signed-off-by: Yedidyah Bar David <[email protected]> --- M packaging/bin/engine-backup.sh 1 file changed, 51 insertions(+), 81 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/01/39901/1 diff --git a/packaging/bin/engine-backup.sh b/packaging/bin/engine-backup.sh index 570e6d8..95a5818 100755 --- a/packaging/bin/engine-backup.sh +++ b/packaging/bin/engine-backup.sh @@ -216,18 +216,18 @@ --reports-db-secured-validation validate host for reports --fast-restore the default for backup, equivalent to: - --archive-compressor=gzip \ - --files-compressor=xz \ - --db-dump-format=custom \ - --db-compressor=None \ - --dwh-db-dump-format=custom \ - --dwh-db-compressor=None \ - --reports-db-dump-format=custom \ + --archive-compressor=gzip \\ + --files-compressor=xz \\ + --db-dump-format=custom \\ + --db-compressor=None \\ + --dwh-db-dump-format=custom \\ + --dwh-db-compressor=None \\ + --reports-db-dump-format=custom \\ --reports-db-compressor=None In addition, you should pass, when restoring: - --db-restore-jobs=N \ - --dwh-db-restore-jobs=N \ + --db-restore-jobs=N \\ + --dwh-db-restore-jobs=N \\ --reports-db-restore-jobs=N where 'N' is around number of available cpu cores times 1.5. @@ -242,13 +242,13 @@ Need to test with non-empty DBs. TODO - --archive-compressor=xz \ - --files-compressor=None \ - --db-dump-format=plain \ - --db-compressor=None \ - --dwh-db-dump-format=plain \ - --dwh-db-compressor=None \ - --reports-db-dump-format=plain \ + --archive-compressor=xz \\ + --files-compressor=None \\ + --db-dump-format=plain \\ + --db-compressor=None \\ + --dwh-db-dump-format=plain \\ + --dwh-db-compressor=None \\ + --reports-db-dump-format=plain \\ --reports-db-compressor=None ENVIRONMENT VARIABLES @@ -703,31 +703,28 @@ local format="$7" local pgdump_log="${TEMP_FOLDER}/pgdump.log" + + pg_cmd() { + local cmd="$1" + shift + "${cmd}" -w -U "${user}" -h "${host}" -p "${port}" -d "${database}" "$@" + } + if [ -n "${compressor}" ]; then - PGPASSFILE="${MYPGPASS}" pg_dump \ + PGPASSFILE="${MYPGPASS}" pg_cmd pg_dump \ -E "UTF8" \ --disable-dollar-quoting \ --disable-triggers \ --format="${format}" \ - -w \ - -U "${user}" \ - -h "${host}" \ - -p "${port}" \ - "${database}" \ 2> "${pgdump_log}" \ | "${compressor}" > "${file}" \ || logdie "${compressor} failed compressing the backup of database ${database}" else - PGPASSFILE="${MYPGPASS}" pg_dump \ + PGPASSFILE="${MYPGPASS}" pg_cmd pg_dump \ -E "UTF8" \ --disable-dollar-quoting \ --disable-triggers \ --format="${format}" \ - -w \ - -U "${user}" \ - -h "${host}" \ - -p "${port}" \ - "${database}" \ 2> "${pgdump_log}" \ > "${file}" \ || logdie "Database ${database} backup failed" @@ -737,6 +734,8 @@ cat "${pgdump_log}" >> "${LOG}" logdie "Database ${database} backup failed" fi + + unset -f pg_cmd } dorestore() { @@ -823,25 +822,17 @@ local host="$2" local port="$3" local database="$4" - PGPASSFILE="${MYPGPASS}" psql \ - -w \ - -U "${user}" \ - -h "${host}" \ - -p "${port}" \ - -d "${database}" \ - -c "select 1" \ - >> "${LOG}" 2>&1 \ + + pg_cmd() { + local cmd="$1" + shift + "${cmd}" -w -U "${user}" -h "${host}" -p "${port}" -d "${database}" "$@" + } + + PGPASSFILE="${MYPGPASS}" pg_cmd psql -c "select 1" >> "${LOG}" 2>&1 \ || logdie "Can't connect to database '${database}'. Please see '${0} --help'." - PGPASSFILE="${MYPGPASS}" psql \ - -w \ - -t \ - -U "${user}" \ - -h "${host}" \ - -p "${port}" \ - -d "${database}" \ - -c "show lc_messages" \ - 2> /dev/null \ + PGPASSFILE="${MYPGPASS}" pg_cmd psql -t -c "show lc_messages" 2> /dev/null \ | grep -q '^ *en_US.UTF-8$' \ || logdie "lc_messages is set to an unsupported value in postgresql.conf. Please set it to en_US.UTF-8 and restart postgresql." @@ -851,15 +842,12 @@ __EOF ) - PGPASSFILE="${MYPGPASS}" pg_dump \ - -U "${user}" \ - -h "${host}" \ - -p "${port}" \ - -s \ - "${database}" | \ + PGPASSFILE="${MYPGPASS}" pg_cmd pg_dump -s \ grep -Evi "${IGNORED_PATTERN}" | \ grep -iq '^create' && \ logdie "Database '${database}' is not empty" + + unset -f pg_cmd } verifyVersion() { @@ -891,52 +879,32 @@ local compressor="$7" local format="$8" + pg_cmd() { + local cmd="$1" + shift + "${cmd}" -w -U "${user}" -h "${host}" -p "${port}" -d "${database}" "$@" + } + log "restoreDB: backupfile ${backupfile} user ${user} host ${host} port ${port} database ${database} orig_user ${orig_user}" local pgrestorelog="${TEMP_FOLDER}/pg-restore-log" if [ "${format}" = "plain" ]; then if [ -z "${compressor}" ]; then - PGPASSFILE="${MYPGPASS}" psql \ - -f "${backupfile}" \ - -w \ - -U "${user}" \ - -h "${host}" \ - -p "${port}" \ - -d "${database}" \ - > "${pgrestorelog}" 2>&1 \ + PGPASSFILE="${MYPGPASS}" pg_cmd psql -f "${backupfile}" > "${pgrestorelog}" 2>&1 \ || logdie "Database ${database} restore failed" else # Requires the compressor to support '-d'. All our current ones do. "${compressor}" -d < "${backupfile}" | \ - PGPASSFILE="${MYPGPASS}" psql \ - -w \ - -U "${user}" \ - -h "${host}" \ - -p "${port}" \ - -d "${database}" \ - > "${pgrestorelog}" 2>&1 \ + PGPASSFILE="${MYPGPASS}" pg_cmd psql > "${pgrestorelog}" 2>&1 \ || logdie "Database ${database} restore failed" fi elif [ "${format}" = "custom" ]; then if [ -z "${compressor}" ]; then - PGPASSFILE="${MYPGPASS}" pg_restore \ - -w \ - -U "${user}" \ - -h "${host}" \ - -p "${port}" \ - -d "${database}" \ - "${backupfile}" \ - > "${pgrestorelog}" 2>&1 + PGPASSFILE="${MYPGPASS}" pg_cmd pg_restore "${backupfile}" > "${pgrestorelog}" 2>&1 else # Requires the compressor to support '-d'. All our current ones do. "${compressor}" -d < "${backupfile}" | \ - PGPASSFILE="${MYPGPASS}" pg_restore \ - -w \ - -U "${user}" \ - -h "${host}" \ - -p "${port}" \ - -d "${database}" \ - > "${pgrestorelog}" 2>&1 + PGPASSFILE="${MYPGPASS}" pg_cmd pg_restore > "${pgrestorelog}" 2>&1 fi else logdie "Unsupported format ${format}" @@ -969,6 +937,8 @@ ) local numerrors=$(grep 'ERROR: ' "${pgrestorelog}" | grep -Ev "${IGNORED_ERRORS}" | wc -l) [ ${numerrors} -ne 0 ] && logdie "Errors while restoring database ${database}" + + unset -f pg_cmd } cleanDbTempData() { -- To view, visit https://gerrit.ovirt.org/39901 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I168c89a988854f2d912e31fa9a02b89c9d924dbb Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Yedidyah Bar David <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
