Yedidyah Bar David has uploaded a new change for review. Change subject: packaging: engine-backup: log postgres commands ......................................................................
packaging: engine-backup: log postgres commands Log postgres commands (pg_dump, psql) stdout/stderr directly to main log if we do not parse them, instead of using a temporary log and appending it. If we do parse them, do not die on error before appending to main log. Bug-Url: https://bugzilla.redhat.com/1222554 Change-Id: Ic45bdf97523a8a5ce1edcf03af8876414b9302ec Signed-off-by: Yedidyah Bar David <d...@redhat.com> --- M packaging/bin/engine-backup.sh 1 file changed, 14 insertions(+), 20 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/17/41117/1 diff --git a/packaging/bin/engine-backup.sh b/packaging/bin/engine-backup.sh index d507525..22e3e31 100755 --- a/packaging/bin/engine-backup.sh +++ b/packaging/bin/engine-backup.sh @@ -756,6 +756,7 @@ local format="$7" local pgdump_log="${TEMP_FOLDER}/pgdump.log" + local failed_msg= if [ -n "${compressor}" ]; then pg_cmd pg_dump \ @@ -767,7 +768,7 @@ --no-privileges \ 2> "${pgdump_log}" \ | "${compressor}" > "${file}" \ - || logdie "${compressor} failed compressing the backup of database ${database}" + || failed_msg="${compressor} failed compressing the backup of database ${database}" else pg_cmd pg_dump \ -E "UTF8" \ @@ -778,13 +779,14 @@ --no-privileges \ 2> "${pgdump_log}" \ > "${file}" \ - || logdie "Database ${database} backup failed" + || failed_msg="Database ${database} backup failed" fi if [ -s "${pgdump_log}" ]; then cat "${pgdump_log}" >> "${LOG}" - logdie "Database ${database} backup failed" + [ -z "${failed_msg}" ] && failed_msg="Database ${database} backup failed" fi + [ -n "${failed_msg}" ] && logdie "${failed_msg}" } dorestore() { @@ -1002,16 +1004,17 @@ log "restoreDB: backupfile ${backupfile} user ${user} host ${host} port ${port} database ${database} orig_user ${orig_user} compressor ${compressor} format ${format} jobsnum ${jobsnum}" local pgrestorelog="${TEMP_FOLDER}/pg-restore-log" + local failed_msg= if [ "${format}" = "plain" ]; then if [ -z "${compressor}" ]; then pg_cmd psql -f "${backupfile}" > "${pgrestorelog}" 2>&1 \ - || logdie "Database ${database} restore failed" + || failed_msg="Database ${database} restore failed" else # Requires the compressor to support '-d'. All our current ones do. "${compressor}" -d < "${backupfile}" | \ pg_cmd psql > "${pgrestorelog}" 2>&1 \ - || logdie "Database ${database} restore failed" + || failed_msg="Database ${database} restore failed" fi elif [ "${format}" = "custom" ]; then if [ -z "${compressor}" ]; then @@ -1027,6 +1030,8 @@ cat "${pgrestorelog}" >> "${LOG}" 2>&1 \ || logdie "Failed to append pg log to restore log" + + [ -n "${failed_msg}" ] && logdie "${failed_msg}" local IGNORED_ERRORS=$(cat << __EOF | egrep -v '^$|^#' | tr '\012' '|' | sed 's/|$//' language "plpgsql" already exists @@ -1058,16 +1063,13 @@ local port="$3" local database="$4" local tables_to_clean="$5" - local psqllog="${TEMP_FOLDER}/psql-cleanup-log" echo "${tables_to_clean}" | while read -r table; do log "truncating ${table}" pg_cmd psql \ -t \ -c "TRUNCATE TABLE ${table} cascade" \ - > "${psqllog}" 2>&1 \ + >> "${LOG}" 2>&1 \ || logdie "Failed cleaning up ${table}" - cat "${psqllog}" >> "${LOG}" 2>&1 \ - || logdie "Failed to append psql log to restore log" done || logdie "Failed cleaning up temp data" } @@ -1076,23 +1078,18 @@ local host="$2" local port="$3" local database="$4" - local psqllog="${TEMP_FOLDER}/psql-dwhrunning-log" local psqlout="${TEMP_FOLDER}/psql-dwhrunning-out" local sel_q="SELECT var_value FROM dwh_history_timekeeping WHERE var_name='DwhCurrentlyRunning'" local upd_q="UPDATE dwh_history_timekeeping SET var_value='0' WHERE var_name='DwhCurrentlyRunning'" - pg_cmd psql -t -c "${sel_q}" > "${psqlout}" 2> "${psqllog}" \ + pg_cmd psql -t -c "${sel_q}" > "${psqlout}" 2>> "${LOG}" \ || logdie "Failed checking DwhCurrentlyRunning" - cat "${psqllog}" "${psqlout}" >> "${LOG}" 2>&1 \ - || logdie "Failed to append psql log to restore log" if grep -q '1' "${psqlout}"; then output ' - Resetting DwhCurrentlyRunning in dwh_history_timekeeping in engine database' - pg_cmd psql -t -c "${upd_q}" > "${psqllog}" 2>&1 \ + pg_cmd psql -t -c "${upd_q}" >> "${LOG}" 2>&1 \ || logdie "Failed resetting DwhCurrentlyRunning" - cat "${psqllog}" >> "${LOG}" 2>&1 \ - || logdie "Failed to append psql log to restore log" fi } @@ -1383,16 +1380,13 @@ message="$(printf "%s" "${message}" | sed "s/'/''/g")" - local psqllog="${TEMP_FOLDER}/psql-notification-log" local logpath="$(readlink -f ${LOG})" do_notify() { local scope="$1" pg_cmd psql -t -c "SELECT LogEngineBackupEvent('${scope}', now(), ${status}, '${message}', '${ENGINE_FQDN}', '${logpath}');" \ - > "${psqllog}" 2>&1 \ + >> "${LOG}" 2>&1 \ || logdie "Failed notifying engine" - cat "${psqllog}" >> "${LOG}" 2>&1 \ - || logdie "Failed to append psql log to main log" } output "Notifying engine" -- To view, visit https://gerrit.ovirt.org/41117 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic45bdf97523a8a5ce1edcf03af8876414b9302ec Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Yedidyah Bar David <d...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches