}
ManageableRepository repository = repositoryService.getRepository(this.repositoryEntry.getName());
for (String wsName : repository.getWorkspaceNames())
{
WorkspaceContainerFacade wsContainer = repository.getWorkspaceContainer(wsName);
wsContainer.setState(ManageableRepository.SUSPENDED);
workspacesWaits4Resume.add(wsContainer);
}
boolean isSharedDbCleaner = false;
// collect all restorers
for (WorkspaceEntry wEntry : repositoryEntry.getWorkspaceEntries())
{
// get all backupable components
List<Backupable> backupable =
repositoryService.getRepository(this.repositoryEntry.getName()).getWorkspaceContainer(wEntry.getName())
.getComponentInstancesOfType(Backupable.class);
File fullBackupDir =
JCRRestore.getFullBackupFile(new BackupChainLog(workspacesMapping.get(wEntry.getName()))
.getBackupConfig().getBackupDir());
DataRestoreContext context;
if (jdbcConn != null)
{
if (dbType == DatabaseStructureType.SINGLE)
{
context = new DataRestoreContext(
new String[]{
DataRestoreContext.STORAGE_DIR,
DataRestoreContext.DB_CONNECTION,
DataRestoreContext.DB_CLEANER},
new Object[]{
fullBackupDir,
jdbcConn,
isSharedDbCleaner ? new DummyDBCleanerTool() : dbCleaner});
isSharedDbCleaner = true;
}
else
{
context = new DataRestoreContext(
new String[]{
DataRestoreContext.STORAGE_DIR,
DataRestoreContext.DB_CONNECTION},
new Object[]{
fullBackupDir,
jdbcConn});
}
}
else
{
context = new DataRestoreContext(
new String[] {DataRestoreContext.STORAGE_DIR},
new Object[] {fullBackupDir});
}
for (Backupable component : backupable)
{
dataRestorer.add(component.getDataRestorer(context));
}
}
for (DataRestore restorer : dataRestorer)
{
restorer.clean();
}
for (DataRestore restorer : dataRestorer)
{
restorer.restore();
}
for (DataRestore restorer : dataRestorer)
{
restorer.commit();
}
// resume components
for (WorkspaceContainerFacade wsContainer : workspacesWaits4Resume)
{
wsContainer.setState(ManageableRepository.ONLINE);
}
// incremental restore
for (WorkspaceEntry wEntry : repositoryEntry.getWorkspaceEntries())
{
repositoryService.getRepository(this.repositoryEntry.getName()).getWorkspaceContainer(wEntry.getName())
.getComponentInstancesOfType(Backupable.class);
DataManager dataManager =
(WorkspacePersistentDataManager)repositoryService.getRepository(this.repositoryEntry.getName())
.getWorkspaceContainer(wEntry.getName()).getComponent(WorkspacePersistentDataManager.class);
File storageDir =
JCRRestore.getFullBackupFile(new BackupChainLog(workspacesMapping.get(wEntry.getName()))
.getBackupConfig().getBackupDir());
FileCleanerHolder cleanerHolder =
(FileCleanerHolder)repositoryService.getRepository(this.repositoryEntry.getName())
.getWorkspaceContainer(wEntry.getName()).getComponent(FileCleanerHolder.class);
JCRRestore restorer = new JCRRestore(dataManager, cleanerHolder.getFileCleaner());
for (File incrBackupFile : JCRRestore.getIncrementalFiles(storageDir))
{
restorer.incrementalRestore(incrBackupFile);
}
}
}
catch (Throwable t) //NOSONAR
{
// rollback
for (DataRestore restorer : dataRestorer)
{
try
{
restorer.rollback();
}
catch (BackupException e)
{
LOG.error("Can't rollback changes", e);
}
}
throw new RepositoryRestoreExeption("Repository " + repositoryEntry.getName() + " was not restored", t);
}
finally
{
// close
for (DataRestore restorer : dataRestorer)
{
try
{
restorer.close();
}
catch (BackupException e)
{
LOG.error("Can't close restorer", e);
}
}
try
{
for (WorkspaceContainerFacade wsContainer : workspacesWaits4Resume)
{
wsContainer.setState(ManageableRepository.ONLINE);
}
}
catch (RepositoryException e)
{
LOG.error("Can't resume repository", e);