From cf81060987afd88d07804f08103299fd7f2514ba Mon Sep 17 00:00:00 2001 From: felmer <felmer> Date: Mon, 5 Dec 2016 13:45:50 +0000 Subject: [PATCH] SSDM-4444: Copy html/etc folders to backup and restore them after upgrade SVN: 37439 --- .../resource/installer/bin/backup-config.sh | 6 +- .../installer/bin/common-functions.sh | 224 ++++++++++++++++++ .../bin/restore-config-from-backup.sh | 11 +- 3 files changed, 234 insertions(+), 7 deletions(-) diff --git a/installation/resource/installer/bin/backup-config.sh b/installation/resource/installer/bin/backup-config.sh index dd0c82e9183..8a3d3ff2f1b 100755 --- a/installation/resource/installer/bin/backup-config.sh +++ b/installation/resource/installer/bin/backup-config.sh @@ -3,8 +3,8 @@ CONF=$1 if [ "$CONF" == "" ]; then - echo Error: directory where configuration should be backed up has not been specified! - exit 1 + echo Error: directory where configuration should be backed up has not been specified! + exit 1 fi mkdir -p $CONF @@ -42,6 +42,8 @@ if [ -d $ROOT/openBIS-server ]; then copyIfExists $ROOT/openBIS-server/jetty/etc/openBIS.keystore $CONF/.keystore copyIfExists $ROOT/openBIS-server/jetty/etc/passwd $CONF/ copyIfExists $ROOT/openBIS-server/jetty/etc/web-client.properties $CONF/ + copyIfExists $ROOT/core-plugins/eln-lims/1/as/webapps/eln-lims/html/etc $CONF/eln-lims-etc + copyConfig $ROOT/core-plugins "html/etc$" $CONF/core-plugins cp -R $ROOT/openBIS-server/jetty/start.d $CONF/start.d fi diff --git a/installation/resource/installer/bin/common-functions.sh b/installation/resource/installer/bin/common-functions.sh index 07eae3ee48e..a4bb0f9be60 100644 --- a/installation/resource/installer/bin/common-functions.sh +++ b/installation/resource/installer/bin/common-functions.sh @@ -166,6 +166,230 @@ copyFolderIfExists() fi } +POSTGRES_BIN=`cat $BASE/postgres_bin_path.txt` + +# +# Removes white trailing and leading white spaces. +# +# This function should be used as follows: +# +# trimmedString=$(trim $someString) +# +trim() +{ + echo "$1" | sed 's/^ *//g' | sed 's/ *$//g' +} + +# +# Checks whether the first argument, a comma-separated list of items contains the second argument +# as an item. Returns TRUE if this is the case. Trailing and leading +# whitespace of list items are ignored. +# +# This function should be used as follows: +# +# result=$(contains " abc, def , ghi " "abc") +# +contains() +{ + local list="$1" + local item="$2" + while true; do + local part="${list%%,*}" + local firstItem=$(trim $part) + list="${list#*,}" + if [ "$firstItem" == "$item" ]; then + echo "TRUE" + return + fi + if [ "$part" == "$list" ]; then + echo "FALSE" + return + fi + done +} + +# +# 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 $password) == "TRUE" ]; then doBackup; fi +# +databaseExist() +{ + local host=$1 + local port=$2 + local database=$3 + local owner=$4 + 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" + fi +} + +# +# Run psql command using POSTGRES_BIN path +# +exe_psql() +{ + executable="$POSTGRES_BIN/psql" + if [ ! -x "$executable" ]; then + executable=psql + fi + execute "$executable" "$@" +} + +# +# Run pg_dump command using POSTGRES_BIN path +# +exe_pg_dump() +{ + executable="$POSTGRES_BIN/pg_dump" + if [ ! -x "$executable" ]; then + executable=pg_dump + fi + execute "$executable" "$@" +} + +execute() +{ + executable=$1 + shift + if [ "${1%=*}" == "PGPASSWORD" ]; then + export $1 + shift + fi + echo "$executable" "$@" + "$executable" "$@" + unset PGPASSWORD +} + +# +# Default openBIS operations like creating a backup or upgrading to a newer version often +# need to be customized by a specific project (e.g. screening). This function provides +# infrastructure for such functionality. +# +# The original script (e.g. upgrade.sh) includes a call specifying a filemask e.g. +# +# executeScriptHooks "Executing upgrade post-hook " "$ROOT/servers/*/bin/post-install-*.sh" +# +# Parameters +# $1 - an appropriate log message to identify the nature of the scripts being executed +# $2 - a file mask specifying the scripts to be executed (see the example above) +executeScriptHooks() +{ + if [ "$1" == "" ]; then + echo "ERROR: You must specify a log message when calling 'executeScriptHooks'" + exit 1 + fi + if [ "$2" == "" ]; then + echo "ERROR: You must specify a file mask for scripts to be executed" + exit 1 + fi + + logmessage=$1 + filemask=$2 + + for hook in $filemask; do + echo "$logmessage $hook" + bash $hook + done +} + +# +# Copies a file (first parameter) to a destination (second parameter). +# Does nothing if file does not exist. Will follow symbolic links. +# +copyFileIfExists() +{ + if [ -e "$1" ]; then + cp -p "$1" "$2" + fi +} + +# +# Copies a file/folder (first parameter) to a destination (second parameter). +# Does nothing if file/folder does not exist. +# +copyIfExists() +{ + if [ -e "$1" ]; then + cp -R "$1" "$2" + fi +} + +# +# overwrites a folder (second parameter) with first parameter +# +copyFolderIfExists() +{ + if [ -e "$1" ]; then + rm -r "$2" + cp -R "$1" "$2" + fi +} + +# +# copy configurations +# +copyConfig() +{ + root="$1" + pathPattern="$2" + destination="$3" + for f in `find $root | grep "$pathPattern"`; do + d="$destination/${f#$root}" + rm -rf "$d" + d="${d%/*}" + mkdir -p "$d" + copyIfExists $f "$d" + done +} + +# +# Installs openBIS server to a given destination +# The function assumes that the openBIS-server*.zip file is already present in the destination. +# +installOpenBisServer() +{ + if [ "$1" == "" ]; then + echo "ERROR: You must specify a folder to install openBIS-server" + exit 1 + fi + + INSTALL_DIR=$1 + TMP_EXTRACT=$INSTALL_DIR/tmp-extract + echo Installing openBIS Application Server to $INSTALL_DIR + + mkdir -p "$TMP_EXTRACT" + mkdir $INSTALL_DIR/openBIS-server + unzip $INSTALL_DIR/openBIS-*.zip -d "$TMP_EXTRACT" + $TMP_EXTRACT/openBIS-server/install.sh $INSTALL_DIR/openBIS-server + + rm -rf "$TMP_EXTRACT" +} + +# +# Installs Data Store Server to a given destination +# The function assumes that the datastore-server*.zip file is already present in the destination. +# +installDataStoreServer() +{ + if [ "$1" == "" ]; then + echo "ERROR: You must specify a folder to install Data Store Server" + exit 1 + fi + + INSTALL_DIR=$1 + echo Installing openBIS Datastore Server to $INSTALL_DIR + unzip $INSTALL_DIR/datastore*.zip -d $INSTALL_DIR +} + # # Installs openBIS server to a given destination diff --git a/installation/resource/installer/bin/restore-config-from-backup.sh b/installation/resource/installer/bin/restore-config-from-backup.sh index 62a061570fd..860f04392df 100755 --- a/installation/resource/installer/bin/restore-config-from-backup.sh +++ b/installation/resource/installer/bin/restore-config-from-backup.sh @@ -4,8 +4,8 @@ CONF=$1 if [ "$CONF" == "" ]; then - echo Error: directory from which configuration should be restored has not been specified! - exit 1 + echo Error: directory from which configuration should be restored has not been specified! + exit 1 fi if [ -n "$(readlink $0)" ]; then @@ -47,6 +47,7 @@ if [ -d $ROOT/openBIS-server ]; then copyIfExists $CONF/web-client.properties $ROOT/openBIS-server/jetty/etc/ copyIfExists $CONF/capabilities $ROOT/openBIS-server/jetty/etc/ copyIfExists $CONF/dss-datasource-mapping $ROOT/openBIS-server/jetty/etc/ + copyConfig $CONF/core-plugins "html/etc$" $ROOT/core-plugins copyFolderIfExists $CONF/start.d $ROOT/openBIS-server/jetty/start.d fi @@ -60,7 +61,7 @@ copyIfExists $CONF/ext-lib $ROOT/datastore_server # -- ELN-LIMS if [ -d $ROOT/core-plugins/eln-lims/1/as/webapps/eln-lims/html/etc ]; then - if [ -d $CONF/../eln-lims/1/as/webapps/eln-lims/html/etc ]; then - cp $CONF/../eln-lims/1/as/webapps/eln-lims/html/etc/* $ROOT/core-plugins/eln-lims/1/as/webapps/eln-lims/html/etc/ - fi + if [ -d $CONF/../eln-lims/1/as/webapps/eln-lims/html/etc ]; then + cp $CONF/../eln-lims/1/as/webapps/eln-lims/html/etc/* $ROOT/core-plugins/eln-lims/1/as/webapps/eln-lims/html/etc/ + fi fi \ No newline at end of file -- GitLab