Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
    * Copyright (C) 2009 eXo Platform SAS.
    *
    * This is free software; you can redistribute it and/or modify it
    * under the terms of the GNU Lesser General Public License as
    * published by the Free Software Foundation; either version 2.1 of
    * the License, or (at your option) any later version.
    *
    * This software is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
   * License along with this software; if not, write to the Free
   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   */
  package org.exoplatform.services.jcr.ext.backup.server;
  
  
  import java.io.File;
  import java.util.List;
  
  import javax.jcr.Session;
  import javax.ws.rs.GET;
  import javax.ws.rs.POST;
  import javax.ws.rs.Path;
Created by The eXo Platform SAS.
Date: 24.02.2009

Author(s):
Alex Reshetnyak
Version:
$Id: BackupServer.java 111 2008-11-11 11:11:11Z rainf0x $
  
  
  @Path("/jcr-backup/")
  public class HTTPBackupAgent implements ResourceContainer
  {

   
Definition the constants.
  
     public static final class Constants
     {

      
The date format RFC_1123.
 
       public static final String DATE_FORMAT_RFC_1123 = "EEE, dd MMM yyyy HH:mm:ss zzz";

      
The base path to this service.
 
       public static final String BASE_URL = "/jcr-backup";

      
Definition the operation types.
 
       public static final class OperationType
       {
         
Start backup operation.
 
          public static final String START_BACKUP = "/start";

         
Start backup repository operation.
 
          public static final String START_BACKUP_REPOSITORY = "/start-backup-repository";

         
Restore operations.
 
          public static final String RESTORE = "/restore";

         
Restore operations from backup set.
 
          public static final String RESTORE_BACKUP_SET = "/restore/backup-set";

         
Restore repository operations.
 
          public static final String RESTORE_REPOSITORY = "/restore-repository";

         
Restore repository operations from backup set.
 
          public static final String RESTORE_REPOSITORY_BACKUP_SET = "/restore-repository/backup-set";

         
Stop backup operations.
 
          public static final String STOP_BACKUP = "/stop";

         
Stop repository backup operations.
 
          public static final String STOP_BACKUP_REPOSITORY = "/stop-backup-repository";

         
The current and completed backups info operation.
 
          public static final String CURRENT_AND_COMPLETED_BACKUPS_INFO = "/info/backup";

         
The current and completed repository backups info operation.
 
          public static final String CURRENT_AND_COMPLETED_BACKUPS_REPOSITORY_INFO = "/info/backup-repository";

         
The current and completed backups info operation for specific workspace.
 
          public static final String CURRENT_AND_COMPLETED_BACKUPS_INFO_ON_WS = "/info/backup";

         
The current backups info operations.
 
          public static final String CURRENT_BACKUPS_INFO = "/info/backup/current";

         
The current repository backups info operations.
 
          public static final String CURRENT_BACKUPS_REPOSITORY_INFO = "/info/backup-repository/current";

         
The current or completed backup info operations.
 
          public static final String CURRENT_OR_COMPLETED_BACKUP_INFO = "/info/backup";

         
The current or completed repository backup info operations.
 
          public static final String CURRENT_OR_COMPLETED_BACKUP_REPOSITORY_INFO = "/info/backup-repository-id";

         
The current restore info operations for specific workspace.
 
          public static final String CURRENT_RESTORE_INFO_ON_WS = "/info/restore";

         
The current restore info operations for specific repository.
 
          public static final String CURRENT_RESTORE_INFO_ON_REPOSITORY = "/info/restore-repository";

         
The current restores info operations.
 
          public static final String CURRENT_RESTORES = "/info/restores";

         
The current repository restores info operations.
 
          public static final String CURRENT_RESTORES_REPOSITORY = "/info/restores-repository";

         
The completed backups info operations.
 
          public static final String COMPLETED_BACKUPS_INFO = "/info/backup/completed";

         
The completed repository backups info operations.
 
          public static final String COMPLETED_BACKUPS_REPOSITORY_INFO = "/info/backup-repository/completed";

         
The backup service info operations.
 
          public static final String BACKUP_SERVICE_INFO = "/info";

         
The drop workspace operations.
 
          public static final String DROP_WORKSPACE = "/drop-workspace";

         
The get default workspace configuration.
 
          public static final String GET_DEFAULT_WORKSPACE_CONFIG = "/info/default-ws-config";

         
The get default repository configuration.
 
          public static final String GET_DEFAULT_REPOSITORY_CONFIG = "/info/default-repository-config";

         
OperationType constructor.
 
          private OperationType()
          {
          }
       }

      
Constants constructor.
 
       private Constants()
       {
       }
    }

   
The apache logger.
 
    private static final Log LOG = ExoLogger.getLogger("exo.jcr.component.ext.HTTPBackupAgent");

   
To disable cache control.
 
    private static final CacheControl noCache;
 
    static
    {
        = new CacheControl();
       .setNoCache(true);
       .setNoStore(true);
    }

   
The repository service.
 
    private RepositoryService repositoryService;

   
The backup manager.
 
    private ExtendedBackupManager backupManager;

   
Will be get session over base authenticate.
 
ReplicationTestService constructor.

Parameters:
repoService the RepositoryService
backupManager the BackupManager
sessionProviderService the ThreadLocalSessionProviderService
 
    public HTTPBackupAgent(RepositoryService repoServiceBackupManager backupManager,
       ThreadLocalSessionProviderService sessionProviderService)
    {
       this. = repoService;
       this. = (ExtendedBackupManagerbackupManager;
       this. = sessionProviderService;
 
       .info("HTTPBackupAgent inited");
    }

   
The start backup.

Parameters:
bConfigBeen BackupConfigBeen, the been with backup configuration.
repository String, the repository name
workspace String, the workspace name
Returns:
Response return the response
 
    @POST
    @RolesAllowed("administrators")
    @Path("/start/{repo}/{ws}")
    public Response start(BackupConfigBean bConfigBeen, @PathParam("repo"String repository,
       @PathParam("ws"String workspace)
    {
       String failMessage;
       Response.Status status;
       Throwable exception;
 
       try
       {
          File backupDir;
 
          if (bConfigBeen.getBackupDir() == null)
          {
             backupDir = .getBackupDirectory();
          }
          else
          {
             backupDir = new File(bConfigBeen.getBackupDir());
             if (!PrivilegedFileHelper.exists(backupDir))
                throw new BackupDirNotFoundException("The backup folder not exists :  "
                         + PrivilegedFileHelper.getAbsolutePath(backupDir));
          }
 
          BackupConfig config = new BackupConfig();
          config.setBackupType(bConfigBeen.getBackupType());
          config.setRepository(repository);
          config.setWorkspace(workspace);
          config.setBackupDir(backupDir);
          config.setIncrementalJobPeriod(bConfigBeen.getIncrementalJobPeriod());
          config.setIncrementalJobNumber(bConfigBeen.getIncrementalRepetitionNumber());
 
          validateRepositoryName(repository);
          validateWorkspaceName(repositoryworkspace);
          validateOneBackupInstants(repositoryworkspace);
 
          BackupChain chain = .startBackup(config);
 
          ShortInfo shortInfo = new ShortInfo(.chain);
 
          return Response.ok(shortInfo).cacheControl().build();
       }
       catch (NoSuchWorkspaceException e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
       catch (LoginException e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
       catch (RepositoryException e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
       catch (RepositoryConfigurationException e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
       catch (WorkspaceRestoreExeption e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
       catch (BackupOperationException e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
       catch (BackupConfigurationException e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
       catch (Throwable e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
 
       .error("Can not start backup"exception);
 
       return Response.status(status).entity("Can not start backup : " + failMessage).type(.)
          .cacheControl().build();
    }

   
The start repository backup.

Parameters:
bConfigBeen BackupConfigBeen, the been with backup configuration.
repository String, the repository name
Returns:
Response return the response
 
    @POST
    @RolesAllowed("administrators")
    @Path("/start-backup-repository/{repo}")
    public Response startBackupRepository(BackupConfigBean bConfigBeen, @PathParam("repo"String repository)
    {
       String failMessage;
       Response.Status status;
       Throwable exception;
 
       try
       {
          File backupDir;
 
          if (bConfigBeen.getBackupDir() == null)
          {
             backupDir = .getBackupDirectory();
          }
          else
          {
             backupDir = new File(bConfigBeen.getBackupDir());
             if (!PrivilegedFileHelper.exists(backupDir))
                throw new BackupDirNotFoundException("The backup folder not exists :  "
                         + PrivilegedFileHelper.getAbsolutePath(backupDir));
          }
 
          RepositoryBackupConfig config = new RepositoryBackupConfig();
          config.setBackupType(bConfigBeen.getBackupType());
          config.setRepository(repository);
          config.setBackupDir(backupDir);
          config.setIncrementalJobPeriod(bConfigBeen.getIncrementalJobPeriod());
          config.setIncrementalJobNumber(bConfigBeen.getIncrementalRepetitionNumber());
 
          validateRepositoryName(repository);
 
          RepositoryBackupChain chain = .startBackup(config);
 
          ShortInfo shortInfo = new ShortInfo(.chain);
 
          return Response.ok(shortInfo).cacheControl().build();
       }
       catch (LoginException e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
       catch (RepositoryException e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
       catch (RepositoryConfigurationException e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
       catch (BackupOperationException e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
       catch (BackupConfigurationException e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
       catch (Throwable e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
 
       .error("Can not start backup"exception);
 
       return Response.status(status).entity("Can not start backup : " + failMessage).type(.)
          .cacheControl().build();
    }

   
The delete workspace.

Parameters:
repository String, the repository name
workspace String, the workspace name
forceSessionClose Boolean, flag to force session close
Returns:
Response return the response
 
    @GET
    @RolesAllowed("administrators")
    @Path("/drop-workspace/{repo}/{ws}/{force-session-close}")
    public Response dropWorkspace(@PathParam("repo"String repository, @PathParam("ws"String workspace,
       @PathParam("force-session-close"Boolean forceSessionClose)
    {
 
       String failMessage;
       Response.Status status;
       Throwable exception;
 
       try
       {
          validateRepositoryName(repository);
          validateWorkspaceName(repositoryworkspace);
 
          if (forceSessionClose)
             forceCloseSession(repositoryworkspace);
 
          RepositoryImpl repositoryImpl = (RepositoryImpl).getRepository(repository);
          repositoryImpl.removeWorkspace(workspace);
          .getConfig().retain(); // save configuration to persistence (file or persister)
 
          return Response.ok().cacheControl().build();
 
       }
       catch (RepositoryException e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
       catch (RepositoryConfigurationException e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
       catch (Throwable e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
 
       .error("Can not drop the workspace '" + "/" + repository + "/" + workspace + "'"exception);
 
       return Response.status(status).entity(
          "Can not drop the workspace '" + "/" + repository + "/" + workspace + "' : " + failMessage).type(
 
    }

   
Restore the workspace.

Parameters:
wEntry WorkspaceEntry, the configuration to restored workspace
repository String, the repository name
backupId String, the identifier of backup
Returns:
Response return the response
 
    @POST
    @RolesAllowed("administrators")
    @Path("/restore/{repo}/{id}")
    public Response restore(WorkspaceEntry wEntry, @PathParam("repo"String repository, @PathParam("id"String backupId)
    {
       String failMessage;
       Response.Status status;
       Throwable exception;
 
       try
       {
          validateOneRestoreInstants(repositorywEntry.getName());
 
          File backupLog = getBackupLogbyId(backupId);
 
          // validate backup log file
          if (backupLog == null)
             throw new BackupLogNotFoundException("The backup log file with id " + backupId + " not exists.");
 
          validateRepositoryName(repository);
 
          if (isWorkspaceExist(repositorywEntry.getName()))
             throw new WorkspaceRestoreException("Workspace " + wEntry.getName() + " already exist!");
 
          BackupChainLog backupChainLog = new BackupChainLog(backupLog);
 
          .restore(backupChainLogrepositorywEntrytrue);
 
          /*
           * Sleeping
           * Restore must be initialized by job thread
           */
 
          Thread.sleep(100);
 
          /*
           * search necessary restore
           */
 
          List<JobWorkspaceRestorerestoreJobs = .getRestores();
          JobWorkspaceRestore restore = null;
          for (JobWorkspaceRestore curRestore : restoreJobs)
          {
             if (curRestore.getRepositoryName().equals(repository)
                && curRestore.getWorkspaceName().equals(wEntry.getName()))
             {
                restore = curRestore;
                break;
             }
          }
 
          if (restore != null)
          {
             ShortInfo info =
                new ShortInfo(.restore.getBackupChainLog(), restore.getStartTime(), restore
                   .getEndTime(), restore.getStateRestore(), restore.getRepositoryName(), restore.getWorkspaceName());
             return Response.ok(info).cacheControl().build();
          }
 
          return Response.ok().cacheControl().build();
       }
       catch (WorkspaceRestoreExeption e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
       catch (RepositoryException e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
       catch (RepositoryConfigurationException e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
       catch (BackupLogNotFoundException e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
       catch (Throwable e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
 
       .error("Can not start restore the workspace '" + "/" + repository + "/" + wEntry.getName()
          + "' from backup log with id '" + backupId + "'"exception);
 
       return Response.status(status).entity(
          "Can not start restore the workspace '" + "/" + repository + "/" + wEntry.getName()
             + "' from backup log with id '" + backupId + "' : " + failMessage).type(.).cacheControl(
          ).build();
    }

   
Restore the workspace.

Parameters:
wEntry WorkspaceEntry, the configuration to restored workspace
repository String, the repository name
backupId String, the identifier of backup
removeExisting Boolean, if 'true' will be removed fully (db, value storage, index) existed workspace.
Returns:
Response return the response
 
    @POST
    @RolesAllowed("administrators")
    @Path("/restore/{repo}/{id}/{remove-Existing}")
    public Response restore(WorkspaceEntry wEntry, @PathParam("repo"String repository,
             @PathParam("id"String backupId, @PathParam("remove-Existing"Boolean removeExisting)
    {
       String failMessage;
       Response.Status status;
       Throwable exception;
 
       try
       {
          validateOneRestoreInstants(repositorywEntry.getName());
 
          File backupLog = getBackupLogbyId(backupId);
 
          // validate backup log file
          if (backupLog == null)
          {
             throw new BackupLogNotFoundException("The backup log file with id " + backupId + " not exists.");
          }
 
          validateRepositoryName(repository);
 
          BackupChainLog backupChainLog = new BackupChainLog(backupLog);
 
          if (removeExisting)
          {
             if (!isWorkspaceExist(repositorywEntry.getName()))
             {
                throw new WorkspaceRestoreException("Workspace " + wEntry.getName() + " is not exist!");
             }
 
             .restoreExistingWorkspace(backupChainLogrepositorywEntrytrue);
          }
          else
          {
             if (isWorkspaceExist(repositorywEntry.getName()))
             {
                throw new Exception("Workspace " + wEntry.getName() + " already exist!");
             }
 
             .restore(backupChainLogrepositorywEntrytrue);
          }
 
          /*
           * Sleeping
           * Restore must be initialized by job thread
           */
 
          Thread.sleep(100);
 
          /*
           * search necessary restore
           */
 
          List<JobWorkspaceRestorerestoreJobs = .getRestores();
          JobWorkspaceRestore restore = null;
          for (JobWorkspaceRestore curRestore : restoreJobs)
          {
             if (curRestore.getRepositoryName().equals(repository)
                      && curRestore.getWorkspaceName().equals(wEntry.getName()))
             {
                restore = curRestore;
                break;
             }
          }
 
          if (restore != null)
          {
             ShortInfo info =
                      new ShortInfo(.restore.getBackupChainLog(), restore.getStartTime(), restore
                               .getEndTime(), restore.getStateRestore(), restore.getRepositoryName(), restore
                               .getWorkspaceName());
             return Response.ok(info).cacheControl().build();
          }
 
          return Response.ok().cacheControl().build();
       }
       catch (WorkspaceRestoreExeption e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
       catch (RepositoryException e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
       catch (RepositoryConfigurationException e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
       catch (BackupLogNotFoundException e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
       catch (Throwable e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
 
       .error("Can not start restore the workspace '" + "/" + repository + "/" + wEntry.getName()
                + "' from backup log with id '" + backupId + "'"exception);
 
       return Response.status(status).entity(
                "Can not start restore the workspace '" + "/" + repository + "/" + wEntry.getName()
                         + "' from backup log with id '" + backupId + "' : " + failMessage).type(.)
                .cacheControl().build();
    }

   
Restore the workspace from backup set with changing configuration (WorkspaceEntry).

Parameters:
wEntry WorkspaceEntry, the configuration to restored workspace
repository String, the repository name
backupSetPath String, the path to backup set
removeExisting Boolean, if 'true' will be removed fully (db, value storage, index) existed workspace.
Returns:
Response return the response
 
    @POST
    @RolesAllowed("administrators")
    @Path("/restore/backup-set/{repo}/{remove-Existing}")
    public Response restoreBackupSet(WorkspaceEntry wEntry, @PathParam("repo"String repository,
             @QueryParam("backup-set-path"String backupSetPathEncoded, @PathParam("remove-Existing"Boolean removeExisting)
    {
       String failMessage;
       Response.Status status;
       Throwable exception;
 
       String backupSetPath = null;
 
       try
       {
          backupSetPath = URLDecoder.decode(backupSetPathEncoded"UTF-8");
       }
       catch (UnsupportedEncodingException e)
       {
          .error("Can not start restore the workspace '" + "/" + repository + "/" + wEntry.getName()
                   + "' from backup set '" + backupSetPath + "'"e);
 
          return Response.status(..).entity(
                   "Can not start restore the workspace '" + "/" + repository + "/" + wEntry.getName()
                            + "' from backup set '" + backupSetPath + "' : " + e.getMessage())
                   .type(.).cacheControl().build();
       }
 
       try
       {
          validateOneRestoreInstants(repositorywEntry.getName());
 
          File backupSetDir = (new File(backupSetPath));
 
          if (!backupSetDir.exists())
          {
             throw new RestoreConfigurationException("Backup set directory is not exists :" + backupSetPath);
          }
 
          if (!backupSetDir.isDirectory())
          {
             throw new RestoreConfigurationException("Backup set directory is not directory :" + backupSetPath);
          }
 
          File[] cfs = PrivilegedFileHelper.listFiles(backupSetDirnew BackupLogsFilter());
 
          if (cfs.length == 0)
          {
             throw new RestoreConfigurationException("Can not found workspace backup log in directory : "
                      + backupSetPath);
          }
 
          if (cfs.length > 1)
          {
             throw new RestoreConfigurationException(
                      "Backup set directory should contains only one workspace backup log : " + backupSetPath);
          }
 
          validateRepositoryName(repository);
 
          BackupChainLog backupChainLog = new BackupChainLog(cfs[0]);
 
          if (removeExisting)
          {
             if (!isWorkspaceExist(repositorywEntry.getName()))
             {
                throw new WorkspaceRestoreException("Workspace " + wEntry.getName() + " is not exist!");
             }
 
             .restoreExistingWorkspace(backupChainLogrepositorywEntrytrue);
          }
          else
          {
             if (isWorkspaceExist(repositorywEntry.getName()))
             {
                throw new Exception("Workspace " + wEntry.getName() + " already exist!");
             }
 
             .restore(backupChainLogrepositorywEntrytrue);
          }
 
          /*
           * Sleeping
           * Restore must be initialized by job thread
           */
 
          Thread.sleep(100);
 
          /*
           * search necessary restore
           */
 
          List<JobWorkspaceRestorerestoreJobs = .getRestores();
          JobWorkspaceRestore restore = null;
          for (JobWorkspaceRestore curRestore : restoreJobs)
          {
             if (curRestore.getRepositoryName().equals(repository)
                      && curRestore.getWorkspaceName().equals(wEntry.getName()))
             {
                restore = curRestore;
                break;
             }
          }
 
          if (restore != null)
          {
             ShortInfo info =
                      new ShortInfo(.restore.getBackupChainLog(), restore.getStartTime(), restore
                               .getEndTime(), restore.getStateRestore(), restore.getRepositoryName(), restore
                               .getWorkspaceName());
             return Response.ok(info).cacheControl().build();
          }
 
          return Response.ok().cacheControl().build();
       }
       catch (WorkspaceRestoreExeption e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
       catch (RepositoryException e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
       catch (RepositoryConfigurationException e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
       catch (BackupLogNotFoundException e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
       catch (Throwable e)
       {
          exception = e;
          status = ..;
          failMessage = e.getMessage();
       }
 
       .error("Can not start restore the workspace '" + "/" + repository + "/" + wEntry.getName()
                + "' from backup set '" + backupSetPath + "'"exception);
 
       return Response.status(status).entity(
                "Can not start restore the workspace '" + "/" + repository + "/" + wEntry.getName()
                         + "' from backup set '" + backupSetPath + "' : " + failMessage).type(.)
                .cacheControl().build();
    }

   
Restore the workspace with original configuration (this configuration was stored in backup chain log).

Parameters:
repository String, the repository name
backupId String, the identifier of backup
removeExisting Boolean, if 'true' will be removed fully (db, value storage, index) existed workspace.
Returns:
Response return the response
   @GET
   @RolesAllowed("administrators")
   @Path("/restore/{id}/{remove-Existing}")
   public Response restore(@PathParam("id"String backupId, @PathParam("remove-Existing"Boolean removeExisting)
   {
      String failMessage;
      Response.Status status;
      Throwable exception;
      String repository = null;
      String workspace = null;
      try
      {
         File backupLog = getBackupLogbyId(backupId);
         // validate backup log file
         if (backupLog == null)
         {
            throw new BackupLogNotFoundException("The backup log file with id " + backupId + " not exists.");
         }
         BackupChainLog backupChainLog = new BackupChainLog(backupLog);
         repository = backupChainLog.getBackupConfig().getRepository();
         workspace = backupChainLog.getBackupConfig().getWorkspace();
         validateOneRestoreInstants(repositoryworkspace);
         validateRepositoryName(repository);
         //workspace name and repository name should equals original names from backup set.
         if (!repository.equals(backupChainLog.getBackupConfig().getRepository()))
         {
            throw new WorkspaceRestoreException("Repository name\"" + repository
                     + "\" should equals original repository name from backup set : \""
                     + backupChainLog.getBackupConfig().getRepository() + "\".");
         }
         if (!workspace.equals(backupChainLog.getBackupConfig().getWorkspace()))
         {
            throw new WorkspaceRestoreException("Workspace name\"" + workspace
                     + "\" should equals original workspace name from backup set : \""
                     + backupChainLog.getBackupConfig().getWorkspace() + "\".");
         }
         if (removeExisting)
         {
            if (!isWorkspaceExist(repositoryworkspace))
            {
               throw new WorkspaceRestoreException("Workspace " + workspace + " is not exists!");
            }
            .restoreExistingWorkspace(backupIdtrue);
         }
         else
         {
            if (isWorkspaceExist(repositoryworkspace))
            {
               throw new Exception("Workspace " + workspace + " already exists!");
            }
            .restoreWorkspace(backupIdtrue);
         }
         /*
          * Sleeping
          * Restore must be initialized by job thread
          */
         Thread.sleep(100);
         /*
          * search necessary restore
          */
         List<JobWorkspaceRestorerestoreJobs = .getRestores();
         JobWorkspaceRestore restore = null;
         for (JobWorkspaceRestore curRestore : restoreJobs)
         {
            if (curRestore.getRepositoryName().equals(repository)
                     && curRestore.getWorkspaceName().equals(workspace))
            {
               restore = curRestore;
               break;
            }
         }
         if (restore != null)
         {
            ShortInfo info =
                     new ShortInfo(.restore.getBackupChainLog(), restore.getStartTime(), restore
                              .getEndTime(), restore.getStateRestore(), restore.getRepositoryName(), restore
                              .getWorkspaceName());
            return Response.ok(info).cacheControl().build();
         }
         return Response.ok().cacheControl().build();
      }
      catch (WorkspaceRestoreExeption e)
      {
         exception = e;
         status = ..;
         failMessage = e.getMessage();
      }
      catch (RepositoryException e)
      {
         exception = e;
         status = ..;
         failMessage = e.getMessage();
      }
      catch (RepositoryConfigurationException e)
      {
         exception = e;
         status = ..;
         failMessage = e.getMessage();
      }
      catch (BackupLogNotFoundException e)
      {
         exception = e;
         status = ..;
         failMessage = e.getMessage();
      }
      catch (Throwable e)
      {
         exception = e;
         status = ..;
         failMessage = e.getMessage();
      }
      .error("Can not start restore the workspace '" + "/" + repository + "/" + workspace
               + "' from backup log with id '" + backupId + "'"exception);
      return Response.status(status).entity(
               "Can not start restore the workspace '" + "/" + repository + "/" + workspace
                        + "' from backup log with id '" + backupId + "' : " + failMessage).type(.)
               .cacheControl().build();
   }

   
Restore the workspace or repository with original configuration (this configuration was stored in backup log).

Parameters:
backupId String, the identifier of backup
removeExisting Boolean, if 'true' will be removed fully (db, value storage, index) existed workspace.
Returns:
Response return the response
   @GET
   @RolesAllowed("administrators")
   @Path("/restore/backup-set/{remove-Existing}")
   public Response restoreFromBackupSet(@QueryParam("backup-set-path"String backupSetPathEncoded,
            @PathParam("remove-Existing"Boolean removeExisting)
   {
      String failMessage = null;
      Response.Status status = null;
      Throwable exception = null;
      
      String backupSetPath = null;
      try
      {
         backupSetPath = URLDecoder.decode(backupSetPathEncoded"UTF-8");
      }
      catch (UnsupportedEncodingException e
      {
         .error("Can not start restore from backup set '" + backupSetPathEncoded + "'"e);
         return Response.status(..).entity(
                  "Can not start restore from backup set  '" + backupSetPathEncoded + "' : " + e.getMessage()).type(
                  .).cacheControl().build();
      }
      File backupSetDir = (new File(backupSetPath));
      File backuplog = null;
      boolean restoreWorkspace = true;
      try
      {
         if (!backupSetDir.exists())
         {
            throw new RestoreConfigurationException("Backup set directory is not exists :" + backupSetPath);
         }
         if (!backupSetDir.isDirectory())
         {
            throw new RestoreConfigurationException("Backup set directory is not directory :" + backupSetPath);
         }
         File[] cfsw = PrivilegedFileHelper.listFiles(backupSetDirnew BackupLogsFilter());
         File[] cfsr = PrivilegedFileHelper.listFiles(backupSetDirnew RepositoryBackupLogsFilter());
         if (cfsw.length == 0 && cfsr.length == 0)
         {
            throw new RestoreConfigurationException("Can not found backup log in directory : " + backupSetPath);
         }
         else if ((cfsw.length == 1 && cfsr.length == 1) || (cfsw.length > 1) || (cfsr.length > 1))
         {
            throw new RestoreConfigurationException("Backup set directory should contains only one backup log : "
                     + backupSetPath);
         }
         else if (cfsw.length != 0 && cfsr.length == 0)
         {
            restoreWorkspace = true;
            backuplog = cfsw[0];
         }
         else if (cfsw.length == 0 && cfsr.length != 0)
         {
            restoreWorkspace = false;
            backuplog = cfsr[0];
         }
      }
      catch (RestoreConfigurationException e)
      {
         exception = e;
         status = ..;
         failMessage = e.getMessage();
      }
      catch (Throwable e)
      {
         exception = e;
         status = ..;
         failMessage = e.getMessage();