Yedidyah Bar David has uploaded a new change for review.

Change subject: packaging: engine-backup: ignore also 'CREATE PROCEDURAL 
LANGUAGE'
......................................................................

packaging: engine-backup: ignore also 'CREATE PROCEDURAL LANGUAGE'

When checking if a database is empty, ignore also 'CREATE PROCEDURAL
LANGUAGE', which is created by default in postgresl 8, in addition
to 'CREATE EXTENSION IF NOT EXISTS plpgsql' which is done in version 9.

Bug-Url: https://bugzilla.redhat.com/1066654
Bug-Url: https://bugzilla.redhat.com/1069131
Change-Id: Ib3772e27d0800792e97ae976f6c40484bd048fb6
Signed-off-by: Yedidyah Bar David <[email protected]>
---
M packaging/bin/engine-backup.sh
1 file changed, 20 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/29/25729/1

diff --git a/packaging/bin/engine-backup.sh b/packaging/bin/engine-backup.sh
index 401986d..854fe98 100755
--- a/packaging/bin/engine-backup.sh
+++ b/packaging/bin/engine-backup.sh
@@ -326,12 +326,18 @@
                >> "${LOG}" 2>&1 \
                || logdie "Can't connect to the database"
 
+       local IGNORED_PATTERN=$(cat << __EOF | tr '\012' '|' | sed 's/|$//'
+^create extension
+^create procedural language
+__EOF
+)
+
        PGPASSFILE="${MYPGPASS}" pg_dump \
                -U "${ENGINE_DB_USER}" \
                -h "${ENGINE_DB_HOST}" \
                -p "${ENGINE_DB_PORT}" \
                "${ENGINE_DB_DATABASE}" | \
-               grep -vi '^create extension' | \
+               grep -Evi "${IGNORED_PATTERN}" | \
                grep -iq '^create' && \
                logdie "Database is not empty"
 }
@@ -345,6 +351,7 @@
 
 restoreDB() {
        local backupfile="$1"
+       local psqllog="${TEMP_FOLDER}/psql-restore-log"
        PGPASSFILE="${MYPGPASS}" psql \
                -w \
                -U "${ENGINE_DB_USER}" \
@@ -352,8 +359,19 @@
                -p "${ENGINE_DB_PORT}" \
                -d "${ENGINE_DB_DATABASE}" \
                -f "${backupfile}" \
-               >> "${LOG}"  2>&1 \
+               >> "${psqllog}"  2>&1 \
                || logdie "Database restore failed"
+
+       cat "${psqllog}" >> "${LOG}"  2>&1 \
+               || logdie "Failed to append psql log to restore log"
+
+       local IGNORED_ERRORS=$(cat << __EOF | tr '\012' '|' | sed 's/|$//'
+language "plpgsql" already exists
+must be owner of language plpgsql
+__EOF
+)
+       local numerrors=$(grep 'ERROR: ' "${psqllog}" | grep -Ev 
"${IGNORED_ERRORS}" | wc -l)
+       [ ${numerrors} -ne 0 ] && logdie "Errors while restoring database 
${ENGINE_DB_DATABASE}"
 }
 
 restoreFiles() {


-- 
To view, visit http://gerrit.ovirt.org/25729
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib3772e27d0800792e97ae976f6c40484bd048fb6
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.3
Gerrit-Owner: Yedidyah Bar David <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to