Skip to content
Snippets Groups Projects
Commit 8f145e44 authored by felmer's avatar felmer
Browse files

SSDM-1388: bug fixed in DBConnectionValidator: trim properties. Using password...

SSDM-1388: bug fixed in DBConnectionValidator: trim properties. Using password for psql and pg_dump.

SVN: 33333
parent f4a86927
No related branches found
No related tags found
No related merge requests found
...@@ -73,11 +73,16 @@ function backupDatabase() { ...@@ -73,11 +73,16 @@ function backupDatabase() {
local host=${hostAndPort%:*} local host=${hostAndPort%:*}
local port=`if [ "${hostAndPort#*:}" == "$host" ]; then echo 5432; else echo ${hostAndPort#*:}; fi` local port=`if [ "${hostAndPort#*:}" == "$host" ]; then echo 5432; else echo ${hostAndPort#*:}; fi`
local username=$(getProperty $DB_PROPS "username") 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 local dumpDir=$BACKUP_DIR/$database
echo "Backing up database $database@$host:$port (for user $username) to $dumpDir..." 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 if [ "$?" -ne 0 ]; then
echo "Failed to backup database '$database' !" echo "Failed to backup database '$database' !"
......
...@@ -41,11 +41,11 @@ contains() ...@@ -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: # 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() databaseExist()
{ {
...@@ -53,7 +53,11 @@ databaseExist() ...@@ -53,7 +53,11 @@ databaseExist()
local port=$2 local port=$2
local database=$3 local database=$3
local owner=$4 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" echo "TRUE"
else else
echo "FALSE" echo "FALSE"
...@@ -66,11 +70,10 @@ databaseExist() ...@@ -66,11 +70,10 @@ databaseExist()
exe_psql() exe_psql()
{ {
executable="$POSTGRES_BIN/psql" executable="$POSTGRES_BIN/psql"
if [ -x "$executable" ]; then if [ ! -x "$executable" ]; then
"$executable" "$@" executable=psql
else
psql "$@"
fi fi
execute "$executable" "$@"
} }
# #
...@@ -80,10 +83,21 @@ exe_pg_dump() ...@@ -80,10 +83,21 @@ exe_pg_dump()
{ {
executable="$POSTGRES_BIN/pg_dump" executable="$POSTGRES_BIN/pg_dump"
if [ -x "$executable" ]; then if [ -x "$executable" ]; then
"$executable" "$@" executable=pg_dump
else fi
pg_dump "$@" execute "$executable" "$@"
}
execute()
{
executable=$1
shift
if [ "${1%=*}" == "PGPASSWORD" ]; then
export $1
shift
fi fi
"$executable" "$@"
unset PGPASSWORD
} }
# #
......
...@@ -101,9 +101,9 @@ public class DBConnectionValidator extends AbstractDataValidator ...@@ -101,9 +101,9 @@ public class DBConnectionValidator extends AbstractDataValidator
return defaultValue; return defaultValue;
} }
String property = Utils.tryToGetServicePropertyOfAS(GlobalInstallationContext.installDir, key); 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; return defaultValue;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment