Kiril Nesenko has uploaded a new change for review. Change subject: Fix restore.sh ......................................................................
Fix restore.sh Change-Id: I5df0eaf0c18d5d009b1e11c86b35beafecb1b6f0 Signed-off-by: Kiril Nesenko <knese...@redhat.com> --- M packaging/dbscripts/restore.sh 1 file changed, 27 insertions(+), 25 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/34/18434/1 diff --git a/packaging/dbscripts/restore.sh b/packaging/dbscripts/restore.sh index 7c329e2..53023fb 100755 --- a/packaging/dbscripts/restore.sh +++ b/packaging/dbscripts/restore.sh @@ -5,7 +5,7 @@ ################################################################################ #include db general functions -pushd $(dirname ${0})>/dev/null +pushd $(dirname ${0}) > /dev/null source ./dbfunctions.sh source ./dbcustomfunctions.sh @@ -30,8 +30,7 @@ printf "\t2) Drop existing DB with dropdb or use the -r flag.\n" printf "\t3) Create a new blank db with the same name with createdb.\n" printf "\t4) Run restore.sh and give new database instance name as the target\n" - popd>/dev/null - exit 0 + popd > /dev/null } restore_from_tar() { @@ -42,9 +41,9 @@ chmod 777 "${dir}" # Check SELinux mode selinux_mode=$(getenforce |tr '[A-Z]' '[a-z]') - if [ "${selinux_mode}" != "disabled" ]; then + if [ "${selinux_mode}" = "enforcing" ]; then # Restoring SELinux default settings - chcon -Rt postgresql_db_t ${dir} + chcon -Rt postgresql_db_t "${dir}" if [ $? -ne 0 ]; then echo "Failed to restore SELinux default settings for ${dir}." exit 5 @@ -62,7 +61,7 @@ # dropping all statements we don't need on a clean DB from teh restore.sql file sed -i -e '/^DROP /d' -e '/^CREATE SCHEMA/d' -e '/^ALTER TABLE ONLY public\./d' -e '/^ALTER FUNCTION public\.uuid_/d' -e '/^CREATE PROCEDURAL LANGUAGE plpgsql/d' -e '/^ALTER PROCEDURAL LANGUAGE plpgsql/d' -e 's/^CREATE FUNCTION uuid_/CREATE OR REPLACE FUNCTION uuid_/g' -e 's?/tmp?'`pwd`'?' -e 's?\$\$PATH\$\$?'`pwd`'?' restore.sql - psql -w -h ${SERVERNAME} -p ${PORT} -U ${USERNAME} -f restore.sql ${DATABASE} + psql -w -h "${SERVERNAME}" -p "${PORT}" -U "${USERNAME}" -f restore.sql "${DATABASE}" res=$? popd rm -rf "${dir}" @@ -83,22 +82,24 @@ esac done -if [[ ! -n "${USERNAME}" || ! -n "${DATABASE}" || ! -n "${FILE}" ]]; then - usage - exit 1 +if [[ -z "${USERNAME}" \ + || -z "${DATABASE}" \ + || -z "${FILE}" ]]; then + usage + exit 1 fi cmd="select datname from pg_database where datname ilike '${DATABASE}';" -res=$(execute_command "${cmd}" template1 ${SERVERNAME} ${PORT}) -res=`echo $res | sed "s@^ @@g"` +res=$(execute_command "${cmd}" template1 "${SERVERNAME}" "${PORT}") +res=$(echo $res | sed "s@^ @@g") -if [ "${res}" = "${DATABASE}" ]; then - if [ ! -n "${REMOVE_EXISTING}" ]; then +if [[ "${res}" = "${DATABASE}" ]]; then + if [[ -z "${REMOVE_EXISTING}" ]]; then echo "Database ${DATABASE} exists, please use -r to force removing it." exit 1 else - dropdb -h ${SERVERNAME} -p ${PORT} -U postgres ${DATABASE} - if [ $? -ne 0 ]; then + dropdb -h "${SERVERNAME}" -p "${PORT}" -U postgres "${DATABASE}" + if [[ $? -ne 0 ]]; then echo "Failed to drop database ${DATABASE}." exit 2 fi @@ -106,29 +107,30 @@ fi echo "Restore of database $DATABASE from $FILE started..." -if file "${FILE}" | grep 'tar'; then - createdb -h ${SERVERNAME} -p ${PORT} -U postgres ${DATABASE} +if file "${FILE}" | grep -q 'tar'; then + createdb -h "${SERVERNAME}" -p "${PORT}" -U postgres "${DATABASE}" # Creating the plpgsql language - createlang --host=${SERVERNAME} --port=${PORT} --dbname=${DATABASE} --username=${USERNAME} plpgsql >& /dev/null + createlang --host="${SERVERNAME}" --port="${PORT}" --dbname="${DATABASE}" --username="${USERNAME}" plpgsql >& /dev/null restore_from_tar + restore_from_tar_res=$? else - psql -w -h ${SERVERNAME} -p ${PORT} -U ${USERNAME} -f ${FILE} + psql -w -h "${SERVERNAME}" -p "${PORT}" -U "${USERNAME}" -f "${FILE}" fi -if [ $? -eq 0 ];then - echo "Restore of database $DATABASE from $FILE completed." - if [ ! -n "${OMIT_UPGRADE}" ]; then +if [[ "${restore_from_tar_res}" -eq 0 ]]; then + echo "Restore of database ${DATABASE} from ${FILE} completed." + if [[ ! -n "${OMIT_UPGRADE}" ]]; then echo "Upgrading restored database..." - ./upgrade.sh -s ${SERVERNAME} -p ${PORT} -d ${DATABASE} -u ${USERNAME} -c + ./upgrade.sh -s "${SERVERNAME}" -p "${PORT}" -d "${DATABASE}" -u "${USERNAME}" -c fi - popd>/dev/null + popd > /dev/null else usage exit 3 fi fn_db_set_dbobjects_ownership -if [ $? -ne 0 ]; then +if [[ $? -ne 0 ]]; then echo "An error occurred whilst changing the ownership of objects in the database." exit 4 fi -- To view, visit http://gerrit.ovirt.org/18434 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5df0eaf0c18d5d009b1e11c86b35beafecb1b6f0 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Kiril Nesenko <knese...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches