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 <d...@redhat.com>
---
M packaging/bin/engine-backup.sh
1 file changed, 20 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/77/25677/1

diff --git a/packaging/bin/engine-backup.sh b/packaging/bin/engine-backup.sh
index 86a33e0..305aff9 100755
--- a/packaging/bin/engine-backup.sh
+++ b/packaging/bin/engine-backup.sh
@@ -330,12 +330,18 @@
                >> "${LOG}" 2>&1 \
                || logdie "Can't connect to the database. Please see '${0} 
--help'."
 
+       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"
 }
@@ -349,6 +355,7 @@
 
 restoreDB() {
        local backupfile="$1"
+       local psqllog="${TEMP_FOLDER}/psql-restore-log"
        PGPASSFILE="${MYPGPASS}" psql \
                -w \
                -U "${ENGINE_DB_USER}" \
@@ -356,8 +363,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/25677
To unsubscribe, visit http://gerrit.ovirt.org/settings

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