Search in sources :

Example 1 with BackupConfig

use of jetbrains.buildServer.serverSide.maintenance.BackupConfig in project teamcity-rest by JetBrains.

the class ServerRequest method startBackup.

/**
 * @param fileName               relative file name to save backup to (will be saved into
 *                               the default backup directory (<tt>.BuildServer/backup</tt>
 *                               if not overriden in main-config.xml)
 * @param addTimestamp           whether to add timestamp to the file or not
 * @param includeConfigs         whether to include configs into the backup or not
 * @param includeDatabase        whether to include database into the backup or not
 * @param includeBuildLogs       whether to include build logs into the backup or not
 * @param includePersonalChanges whether to include personal changes into the backup or not
 * @return the resulting file name that the backup will be saved to
 */
@POST
@Path("/backup")
@Produces({ "text/plain" })
@ApiOperation(value = "Start a new backup.", nickname = "startBackup")
public String startBackup(@QueryParam("fileName") String fileName, @QueryParam("addTimestamp") Boolean addTimestamp, @QueryParam("includeConfigs") Boolean includeConfigs, @QueryParam("includeDatabase") Boolean includeDatabase, @QueryParam("includeBuildLogs") Boolean includeBuildLogs, @QueryParam("includePersonalChanges") Boolean includePersonalChanges, @QueryParam("includeRunningBuilds") Boolean includeRunningBuilds, @QueryParam("includeSupplimentaryData") Boolean includeSupplimentaryData) {
    BackupProcessManager backupManager = myServiceLocator.getSingletonService(BackupProcessManager.class);
    BackupConfig backupConfig = new BackupConfig();
    if (StringUtil.isNotEmpty(fileName)) {
        if (!TeamCityProperties.getBoolean("rest.request.server.backup.allowAnyTargetPath")) {
            File backupDir = new File(myDataProvider.getBean(ServerPaths.class).getBackupDir());
            try {
                FileSecurityUtil.checkInsideDirectory(FileUtil.resolvePath(backupDir, fileName), backupDir);
            } catch (Exception e) {
                // the message contains absolute paths
                if (myPermissionChecker.hasGlobalPermission(Permission.MANAGE_SERVER_INSTALLATION)) {
                    throw e;
                }
                throw new BadRequestException("Target file name (" + fileName + ") should be relative path.", null);
            }
        }
        if (addTimestamp != null) {
            backupConfig.setFileName(fileName, addTimestamp);
        } else {
            backupConfig.setFileName(fileName);
        }
    } else {
        throw new BadRequestException("No target file name specified.", null);
    }
    if (includeConfigs != null)
        backupConfig.setIncludeConfiguration(includeConfigs);
    if (includeDatabase != null)
        backupConfig.setIncludeDatabase(includeDatabase);
    if (includeBuildLogs != null)
        backupConfig.setIncludeBuildLogs(includeBuildLogs);
    if (includePersonalChanges != null)
        backupConfig.setIncludePersonalChanges(includePersonalChanges);
    if (includeRunningBuilds != null)
        backupConfig.setIncludeRunningBuilds(includeRunningBuilds);
    if (includeSupplimentaryData != null)
        backupConfig.setIncludeSupplementaryData(includeSupplimentaryData);
    try {
        backupManager.startBackup(backupConfig);
    } catch (MaintenanceProcessAlreadyRunningException e) {
        throw new InvalidStateException("Cannot start backup because another maintenance process is in progress", e);
    }
    return backupConfig.getResultFileName();
}
Also used : BackupConfig(jetbrains.buildServer.serverSide.maintenance.BackupConfig) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) MaintenanceProcessAlreadyRunningException(jetbrains.buildServer.serverSide.maintenance.MaintenanceProcessAlreadyRunningException) BackupProcessManager(jetbrains.buildServer.serverSide.maintenance.BackupProcessManager) InvalidStateException(jetbrains.buildServer.server.rest.errors.InvalidStateException) File(java.io.File) MaintenanceProcessAlreadyRunningException(jetbrains.buildServer.serverSide.maintenance.MaintenanceProcessAlreadyRunningException) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) InvalidStateException(jetbrains.buildServer.server.rest.errors.InvalidStateException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)1 File (java.io.File)1 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)1 InvalidStateException (jetbrains.buildServer.server.rest.errors.InvalidStateException)1 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)1 BackupConfig (jetbrains.buildServer.serverSide.maintenance.BackupConfig)1 BackupProcessManager (jetbrains.buildServer.serverSide.maintenance.BackupProcessManager)1 MaintenanceProcessAlreadyRunningException (jetbrains.buildServer.serverSide.maintenance.MaintenanceProcessAlreadyRunningException)1