Yedidyah Bar David has uploaded a new change for review.

Change subject: packaging: engine-backup: reset DwhCurrentlyRunning
......................................................................

packaging: engine-backup: reset DwhCurrentlyRunning

Reset DwhCurrentlyRunning during restore, to avoid a later engine-setup
failure due to it being set to '1' if dwhd was running during the time
of backup.

Change-Id: I4303279250c1ee1b3b470842e0d8ec17c03dd4d8
Related-To: https://bugzilla.redhat.com/1158985
Signed-off-by: Yedidyah Bar David <d...@redhat.com>
---
M packaging/bin/engine-backup.sh
1 file changed, 37 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/48/40348/1

diff --git a/packaging/bin/engine-backup.sh b/packaging/bin/engine-backup.sh
index af85d30..a786ada 100755
--- a/packaging/bin/engine-backup.sh
+++ b/packaging/bin/engine-backup.sh
@@ -590,7 +590,7 @@
 pg_cmd() {
        local cmd="$1"
        shift
-       "${cmd}" -w -U "${user}" -h "${host}" -p "${port}" -d "${database}" "$@"
+       PGPASSFILE="${MYPGPASS}" "${cmd}" -w -U "${user}" -h "${host}" -p 
"${port}" -d "${database}" "$@"
 }
 
 dobackup() {
@@ -677,7 +677,7 @@
        local pgdump_log="${TEMP_FOLDER}/pgdump.log"
 
        if [ -n "${compressor}" ]; then
-               PGPASSFILE="${MYPGPASS}" pg_cmd pg_dump \
+               pg_cmd pg_dump \
                        -E "UTF8" \
                        --disable-dollar-quoting \
                        --disable-triggers \
@@ -687,7 +687,7 @@
                        | "${compressor}" > "${file}" \
                        || logdie "${compressor} failed compressing the backup 
of database ${database}"
        else
-               PGPASSFILE="${MYPGPASS}" pg_cmd pg_dump \
+               pg_cmd pg_dump \
                        -E "UTF8" \
                        --disable-dollar-quoting \
                        --disable-triggers \
@@ -765,6 +765,7 @@
                if [ -z "${KEEP_TEMPORARY_DATA}" ]; then
                        output "Cleaning up temporary tables in engine database 
'${ENGINE_DB_DATABASE}':"
                        cleanDbTempData "${ENGINE_DB_USER}" "${ENGINE_DB_HOST}" 
"${ENGINE_DB_PORT}" "${ENGINE_DB_DATABASE}" 
"${ENGINE_TABLES_TO_CLEAN_ON_RESTORE}"
+                       resetDwhCurrentlyRunning "${ENGINE_DB_USER}" 
"${ENGINE_DB_HOST}" "${ENGINE_DB_PORT}" "${ENGINE_DB_DATABASE}" 
"${ENGINE_TABLES_TO_CLEAN_ON_RESTORE}"
                fi
        fi
        if [ -n "${SCOPE_DWH_DB}" -a -n "${DWH_DB_USER}" ]; then
@@ -791,10 +792,10 @@
 
        local pgrestorelog="${TEMP_FOLDER}/pg-restore-log"
 
-       PGPASSFILE="${MYPGPASS}" pg_cmd psql -c "select 1" >> "${LOG}" 2>&1 \
+       pg_cmd psql -c "select 1" >> "${LOG}" 2>&1 \
                || logdie "Can't connect to database '${database}'. Please see 
'${0} --help'."
 
-       PGPASSFILE="${MYPGPASS}" pg_cmd psql -t -c "show lc_messages" 2> 
/dev/null \
+       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."
 
@@ -804,7 +805,7 @@
 __EOF
 )
 
-       PGPASSFILE="${MYPGPASS}" pg_cmd pg_dump -s 2> "${pgrestorelog}" | \
+       pg_cmd pg_dump -s 2> "${pgrestorelog}" | \
                grep -Evi "${IGNORED_PATTERN}" | \
                grep -iq '^create' && \
                logdie "Database '${database}' is not empty"
@@ -850,21 +851,21 @@
 
        if [ "${format}" = "plain" ]; then
                if [ -z "${compressor}" ]; then
-                       PGPASSFILE="${MYPGPASS}" pg_cmd psql -f "${backupfile}" 
> "${pgrestorelog}"  2>&1 \
+                       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}" pg_cmd psql > 
"${pgrestorelog}"  2>&1 \
+                               pg_cmd psql > "${pgrestorelog}"  2>&1 \
                                || logdie "Database ${database} restore failed"
                fi
        elif [ "${format}" = "custom" ]; then
                if [ -z "${compressor}" ]; then
-                       PGPASSFILE="${MYPGPASS}" pg_cmd pg_restore --no-owner 
-j "${jobsnum}" "${backupfile}" > "${pgrestorelog}"  2>&1
+                       pg_cmd pg_restore --no-owner -j "${jobsnum}" 
"${backupfile}" > "${pgrestorelog}"  2>&1
                else
                        # Requires the compressor to support '-d'. All our 
current ones do.
                        "${compressor}" -d < "${backupfile}" | \
-                               PGPASSFILE="${MYPGPASS}" pg_cmd pg_restore 
--no-owner > "${pgrestorelog}"  2>&1
+                               pg_cmd pg_restore --no-owner > 
"${pgrestorelog}"  2>&1
                fi
        else
                logdie "Unsupported format ${format}"
@@ -906,7 +907,7 @@
        local psqllog="${TEMP_FOLDER}/psql-cleanup-log"
        echo "${tables_to_clean}" | while read -r table; do
                output "- ${table}"
-               PGPASSFILE="${MYPGPASS}" pg_cmd psql \
+               pg_cmd psql \
                        -t \
                        -c "TRUNCATE TABLE ${table} cascade" \
                        > "${psqllog}"  2>&1 \
@@ -916,6 +917,31 @@
        done || logdie "Failed cleaning up temp data"
 }
 
+resetDwhCurrentlyRunning() {
+       local user="$1"
+       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}" \
+               || 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 \
+                       || logdie "Failed resetting DwhCurrentlyRunning"
+               cat "${psqllog}" >> "${LOG}"  2>&1 \
+                       || logdie "Failed to append psql log to restore log"
+       fi
+}
+
 restoreFiles() {
        local paths="$1"
        local archive="$2"


-- 
To view, visit https://gerrit.ovirt.org/40348
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4303279250c1ee1b3b470842e0d8ec17c03dd4d8
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

Reply via email to