Skip to content
Snippets Groups Projects
Commit ce402b63 authored by anttil's avatar anttil
Browse files

SSDM-360: Upgrading openBIS without database superuser access

SVN: 31621
parent 9ce54623
No related branches found
No related tags found
No related merge requests found
...@@ -60,7 +60,9 @@ function backupDatabase() { ...@@ -60,7 +60,9 @@ function backupDatabase() {
if [ $(checkForBackup $database) == "FALSE" ]; then if [ $(checkForBackup $database) == "FALSE" ]; then
return return
fi fi
if [ $(databaseExist $database) == "TRUE" ]; then
local user_name_for_check=$(getProperty $DB_PROPS "username")
if [ $(databaseExist $database $user_name_for_check) == "TRUE" ]; then
username=$(getProperty $DB_PROPS "username") username=$(getProperty $DB_PROPS "username")
local dumpDir=$BACKUP_DIR/$database local dumpDir=$BACKUP_DIR/$database
......
...@@ -50,7 +50,8 @@ contains() ...@@ -50,7 +50,8 @@ contains()
databaseExist() databaseExist()
{ {
local database=$1 local database=$1
if [ `exe_psql -U postgres -l | eval "awk '/$database /'" | wc -l` -gt 0 ]; then local owner=$2
if [ `exe_psql -U $owner -l | eval "awk '/$database /'" | wc -l` -gt 0 ]; then
echo "TRUE" echo "TRUE"
else else
echo "FALSE" echo "FALSE"
......
...@@ -10,5 +10,6 @@ fi ...@@ -10,5 +10,6 @@ fi
source $BASE/common-functions.sh source $BASE/common-functions.sh
DATABASE="$1" DATABASE="$1"
OWNER="$2"
databaseExist "$DATABASE" databaseExist "$DATABASE" "$OWNER"
\ No newline at end of file \ No newline at end of file
...@@ -37,8 +37,6 @@ public class DBConnectionValidator extends AbstractDataValidator ...@@ -37,8 +37,6 @@ public class DBConnectionValidator extends AbstractDataValidator
private static final String CONNECTION_STRING = "jdbc:postgresql://localhost/template1"; private static final String CONNECTION_STRING = "jdbc:postgresql://localhost/template1";
private static final String POSTGRES_USER = "postgres";
private static final String NO_PASSWORD = ""; private static final String NO_PASSWORD = "";
@Override @Override
...@@ -72,14 +70,8 @@ public class DBConnectionValidator extends AbstractDataValidator ...@@ -72,14 +70,8 @@ public class DBConnectionValidator extends AbstractDataValidator
{ {
return Status.OK; return Status.OK;
} }
String admin = getAdmin();
String adminPassword = getAdminPassword();
String owner = getOwner(); String owner = getOwner();
String ownerPassword = getOwnerPassword(); String ownerPassword = getOwnerPassword();
if (testConnectionOK(admin, adminPassword, "database.admin-user") == false)
{
return Status.ERROR;
}
if (testConnectionOK(owner, ownerPassword, "database.owner") == false) if (testConnectionOK(owner, ownerPassword, "database.owner") == false)
{ {
return Status.ERROR; return Status.ERROR;
...@@ -116,33 +108,6 @@ public class DBConnectionValidator extends AbstractDataValidator ...@@ -116,33 +108,6 @@ public class DBConnectionValidator extends AbstractDataValidator
return password == null ? "" : password; return password == null ? "" : password;
} }
private String getAdmin()
{
String defaultAdmin = POSTGRES_USER;
if (GlobalInstallationContext.isFirstTimeInstallation)
{
return defaultAdmin;
}
String admin =
Utils.tryToGetServicePropertyOfAS(GlobalInstallationContext.installDir,
"database.admin-user");
if (admin != null && admin.length() > 0)
{
return admin;
}
return defaultAdmin;
}
private String getAdminPassword()
{
if (GlobalInstallationContext.isFirstTimeInstallation)
{
return NO_PASSWORD;
}
return Utils.tryToGetServicePropertyOfAS(GlobalInstallationContext.installDir,
"database.admin-password");
}
private boolean testConnectionOK(String username, String password, String messagePostfix) private boolean testConnectionOK(String username, String password, String messagePostfix)
{ {
boolean connected = false; boolean connected = false;
......
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
package ch.systemsx.cisd.openbis.installer.izpack; package ch.systemsx.cisd.openbis.installer.izpack;
import java.util.HashMap;
import java.util.Map;
import com.izforge.izpack.api.data.AutomatedInstallData; import com.izforge.izpack.api.data.AutomatedInstallData;
import com.izforge.izpack.api.data.PanelActionConfiguration; import com.izforge.izpack.api.data.PanelActionConfiguration;
import com.izforge.izpack.api.handler.AbstractUIHandler; import com.izforge.izpack.api.handler.AbstractUIHandler;
...@@ -40,23 +43,31 @@ public class ExecuteBackupAction extends AbstractScriptExecutor implements Panel ...@@ -40,23 +43,31 @@ public class ExecuteBackupAction extends AbstractScriptExecutor implements Panel
String backupFolder = data.getVariable(GlobalInstallationContext.BACKUP_FOLDER_VARNAME); String backupFolder = data.getVariable(GlobalInstallationContext.BACKUP_FOLDER_VARNAME);
String dataBasesToBackup = data.getVariable(SetDatabasesToBackupAction.DATABASES_TO_BACKUP_VARNAME); String dataBasesToBackup = data.getVariable(SetDatabasesToBackupAction.DATABASES_TO_BACKUP_VARNAME);
String console = data.getVariable("SYSTEM_CONSOLE"); String console = data.getVariable("SYSTEM_CONSOLE");
String password =
Utils.tryToGetServicePropertyOfAS(GlobalInstallationContext.installDir,
"database.owner-password");
Map<String, String> env = new HashMap<String, String>();
env.put("PGPASSWORD", password);
if (dataBasesToBackup == null) if (dataBasesToBackup == null)
{ {
if (console == null) if (console == null)
{ {
executeAdminScript(null, script, backupFolder); executeAdminScript(env, script, backupFolder);
} else } else
{ {
executeAdminScript(null, script, backupFolder, "", console); executeAdminScript(env, script, backupFolder, "", console);
} }
} else } else
{ {
if (console == null) if (console == null)
{ {
executeAdminScript(null, script, backupFolder, dataBasesToBackup); executeAdminScript(env, script, backupFolder, dataBasesToBackup);
} else } else
{ {
executeAdminScript(null, script, backupFolder, dataBasesToBackup, console); executeAdminScript(env, script, backupFolder, dataBasesToBackup, console);
} }
} }
} }
......
...@@ -19,7 +19,9 @@ package ch.systemsx.cisd.openbis.installer.izpack; ...@@ -19,7 +19,9 @@ package ch.systemsx.cisd.openbis.installer.izpack;
import java.io.File; import java.io.File;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.apache.commons.io.output.ByteArrayOutputStream; import org.apache.commons.io.output.ByteArrayOutputStream;
...@@ -93,7 +95,18 @@ public class SetDatabasesToBackupAction extends AbstractScriptExecutor implement ...@@ -93,7 +95,18 @@ public class SetDatabasesToBackupAction extends AbstractScriptExecutor implement
return true; return true;
} }
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
executeAdminScript(null, outputStream, outputStream, scriptFile.getAbsolutePath(), database);
String owner =
Utils.tryToGetServicePropertyOfAS(GlobalInstallationContext.installDir,
"database.owner");
String password =
Utils.tryToGetServicePropertyOfAS(GlobalInstallationContext.installDir,
"database.owner-password");
Map<String, String> env = new HashMap<String, String>();
env.put("PGPASSWORD", password);
executeAdminScript(env, outputStream, outputStream, scriptFile.getAbsolutePath(), database, owner);
return outputStream.toString().trim().equals("FALSE") == false; return outputStream.toString().trim().equals("FALSE") == false;
} }
......
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