class RestoreService {

    public synchronized void restoreFromBackup(String fileName) throws BackupFileNotFoundException,
            InterruptedException, RestoreProcessFailedException {
        auditDataHelper.putBackupFilename(backupRepository.getFilePath(fileName));
        String configurationBackupPath = backupRepository.getConfigurationBackupPath();
        String backupFilePath = configurationBackupPath + fileName;
        File backupFile = new File(backupFilePath);
        if (!backupFile.isFile()) {
            throw new BackupFileNotFoundException("backup file " + backupFilePath + " does not exist");
        }
        String[] arguments = buildArguments(backupFilePath);
        try {
            eventPublisher.publishEvent(BackupRestoreEvent.START);
            ExternalProcessRunner.ProcessResult processResult = externalProcessRunner
                    .executeAndThrowOnFailure(configurationRestoreScriptPath, arguments);

            int exitCode = processResult.getExitCode();

            if (log.isInfoEnabled()) {
                String restoreFinishedLogMsg =
                        String.format("Restoring configuration finished with exit status %s", exitCode);
                log.info(restoreFinishedLogMsg);
                log.info(" --- Restore script console output - START --- ");
                log.info(ExternalProcessRunner.processOutputToString(processResult.getProcessOutput()));
                log.info(" --- Restore script console output - END --- ");
            }

            persistenceUtils.evictPoolConnections();

        } catch (ProcessFailedException | ProcessNotExecutableException e) {
            throw new RestoreProcessFailedException(e, "restoring from a backup failed");
        } finally {
            eventPublisher.publishEvent(BackupRestoreEvent.END);
            apiKeyService.clearApiKeyCaches();
            log.debug("Cleared api key caches");
        }
    }

    @Autowired public  RestoreService(ExternalProcessRunner externalProcessRunner,
            @Value("${script.restore-configuration.path}") String configurationRestoreScriptPath,
            @Value("${script.restore-configuration.args}") String configurationRestoreScriptArgs,
            CurrentSecurityServerId currentSecurityServerId, BackupRepository backupRepository,
            ApiKeyService apiKeyService, AuditDataHelper auditDataHelper, PersistenceUtils persistenceUtils,
            ApplicationEventPublisher publisher);

}