From 8f145e443719a1a736884a656d6a3e08a1215d7c Mon Sep 17 00:00:00 2001 From: felmer <felmer> Date: Mon, 26 Jan 2015 11:28:26 +0000 Subject: [PATCH] SSDM-1388: bug fixed in DBConnectionValidator: trim properties. Using password for psql and pg_dump. SVN: 33333 --- .../installer/bin/backup-databases.sh | 9 +++-- .../installer/bin/common-functions.sh | 34 +++++++++++++------ .../izpack/DBConnectionValidator.java | 4 +-- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/installation/resource/installer/bin/backup-databases.sh b/installation/resource/installer/bin/backup-databases.sh index f36b6b1ac68..2e36a2e7187 100755 --- a/installation/resource/installer/bin/backup-databases.sh +++ b/installation/resource/installer/bin/backup-databases.sh @@ -73,11 +73,16 @@ function backupDatabase() { local host=${hostAndPort%:*} local port=`if [ "${hostAndPort#*:}" == "$host" ]; then echo 5432; else echo ${hostAndPort#*:}; fi` local username=$(getProperty $DB_PROPS "username") - if [ $(databaseExist $host $port $database $username) == "TRUE" ]; then + local password=$(getProperty $DB_PROPS "password") + if [ $(databaseExist $host $port $database $username $password) == "TRUE" ]; then local dumpDir=$BACKUP_DIR/$database echo "Backing up database $database@$host:$port (for user $username) to $dumpDir..." - exe_pg_dump -U $username -h $host -p $port -Fd $database $PG_DUMP_OPTION -f $dumpDir + pgpw="" + if [ $password != "" ]; then + pgpw="PGPASSWORD=$password" + fi + exe_pg_dump $pgpw -U $username -h $host -p $port -Fd $database $PG_DUMP_OPTION -f $dumpDir if [ "$?" -ne 0 ]; then echo "Failed to backup database '$database' !" diff --git a/installation/resource/installer/bin/common-functions.sh b/installation/resource/installer/bin/common-functions.sh index 7a92084b49d..86b82ad05a3 100644 --- a/installation/resource/installer/bin/common-functions.sh +++ b/installation/resource/installer/bin/common-functions.sh @@ -41,11 +41,11 @@ contains() } # -# Returns TRUE if the specified database exists. +# Returns TRUE if the specified database exists. Password argument is optional # # This function should be used as follows: # -# if [ $(databaseExist localhost 5432 "openbis_prod" $owner) == "TRUE" ]; then doBackup; fi +# if [ $(databaseExist localhost 5432 "openbis_prod" $owner $password) == "TRUE" ]; then doBackup; fi # databaseExist() { @@ -53,7 +53,11 @@ databaseExist() local port=$2 local database=$3 local owner=$4 - if [ `exe_psql -U $owner -h $host -p $port -l | eval "awk '/$database /'" | wc -l` -gt 0 ]; then + pgpw="" + if [ $# -eq 5 ]; then + pgpw="PGPASSWORD=$5" + fi + if [ `exe_psql $pgpw -w -U $owner -h $host -p $port -l | eval "awk '/$database /'" | wc -l` -gt 0 ]; then echo "TRUE" else echo "FALSE" @@ -66,11 +70,10 @@ databaseExist() exe_psql() { executable="$POSTGRES_BIN/psql" - if [ -x "$executable" ]; then - "$executable" "$@" - else - psql "$@" + if [ ! -x "$executable" ]; then + executable=psql fi + execute "$executable" "$@" } # @@ -80,10 +83,21 @@ exe_pg_dump() { executable="$POSTGRES_BIN/pg_dump" if [ -x "$executable" ]; then - "$executable" "$@" - else - pg_dump "$@" + executable=pg_dump + fi + execute "$executable" "$@" +} + +execute() +{ + executable=$1 + shift + if [ "${1%=*}" == "PGPASSWORD" ]; then + export $1 + shift fi + "$executable" "$@" + unset PGPASSWORD } # diff --git a/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/DBConnectionValidator.java b/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/DBConnectionValidator.java index 603f21b40c4..529ddc185ce 100644 --- a/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/DBConnectionValidator.java +++ b/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/DBConnectionValidator.java @@ -101,9 +101,9 @@ public class DBConnectionValidator extends AbstractDataValidator return defaultValue; } String property = Utils.tryToGetServicePropertyOfAS(GlobalInstallationContext.installDir, key); - if (property != null && property.length() > 0) + if (property != null && property.trim().length() > 0) { - return property; + return property.trim(); } return defaultValue; } -- GitLab