public void runRestoreScript(BackupBean backup, boolean verify, boolean noRestart) { if (verify) { // run directly restore script if validating archives only, otherwise it needs to be // run as root, so drive this through cfengine String cmdLine = composeCmdLine(backup, verify, noRestart); try { File script = new File(m_binDirectory, RESTORE_SCRIPT); Process process = Runtime.getRuntime().exec(script.getAbsolutePath() + SEPARATOR + cmdLine); int code = process.waitFor(); if (code == INCOMPATIBLE_VERSIONS && verify) { throw new UserException("&message.wrongVersion"); } else if (code == INVALID_CONFIGURATION_ARCHIVE && verify) { throw new UserException("&message.wrongConfigurationFileToRestore"); } else if (code == INVALID_VOICEMAIL_ARCHIVE && verify) { throw new UserException("&message.wrongVoicemailFileToRestore"); } } catch (IOException e) { LOG.error(String.format(ERROR, cmdLine)); throw new UserException("&message.noScriptFound"); } catch (InterruptedException e) { LOG.warn(String.format(ERROR, cmdLine)); } } else { Writer wtr = null; try { Location primary = m_locationsManager.getPrimaryLocation(); File f = new File( ((ConfigManager) m_configCommands).getLocationDataDirectory(primary), "restore.ini"); wtr = new FileWriter(f); wtr.write(composeCmdLine(backup, verify, noRestart)); wtr.flush(); m_configCommands.runRestoreScript(primary); } catch (IOException ex) { LOG.error(String.format(ERROR, ex.getMessage())); throw new UserException("&err.restore.failed"); } finally { IOUtils.closeQuietly(wtr); } } }