diff --git a/installation/resource/installer/bin/backup-databases.sh b/installation/resource/installer/bin/backup-databases.sh index f36b6b1ac68c33b365824af5d53d0fc2ef5af096..2e36a2e7187735b26318ab56c88c8b2d2aebeaa4 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 7a92084b49d9d45e6a20fd927f0008c08d58a967..86b82ad05a327ca6973c8237a703a1ed6bc1c8be 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 603f21b40c435cb4cf30933e660850d065fb49c4..529ddc185ced4882313a616b82f9cfd682539fcb 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; }