Author: areshetnyak
Date: 2010-11-25 10:27:54 -0500 (Thu, 25 Nov 2010)
New Revision: 3569
Added:
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/ExtendedBackupManager.java
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/WorkspaceRestoreException.java
Modified:
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/BackupChainLog.java
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChainLog.java
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupChainImpl.java
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/RepositoryBackupChainImpl.java
jcr/branches/1.12.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupTestCase.java
jcr/branches/1.12.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java
Log:
JCR-1502 : Changes for "The JCR backupset should be fully independent" was
committed.
Modified:
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/BackupChainLog.java
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/BackupChainLog.java 2010-11-25
15:11:40 UTC (rev 3568)
+++
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/BackupChainLog.java 2010-11-25
15:27:54 UTC (rev 3569)
@@ -18,15 +18,14 @@
*/
package org.exoplatform.services.jcr.ext.backup;
-import org.exoplatform.services.jcr.impl.util.JCRDateFormat;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
@@ -44,6 +43,20 @@
import javax.xml.stream.XMLStreamWriter;
import javax.xml.stream.events.StartElement;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.util.JCRDateFormat;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.exoplatform.ws.frameworks.json.JsonHandler;
+import org.exoplatform.ws.frameworks.json.JsonParser;
+import org.exoplatform.ws.frameworks.json.impl.BeanBuilder;
+import org.exoplatform.ws.frameworks.json.impl.JsonDefaultHandler;
+import org.exoplatform.ws.frameworks.json.impl.JsonException;
+import org.exoplatform.ws.frameworks.json.impl.JsonGeneratorImpl;
+import org.exoplatform.ws.frameworks.json.impl.JsonParserImpl;
+import org.exoplatform.ws.frameworks.json.value.JsonValue;
+
/**
* Created by The eXo Platform SARL .<br/>
*
@@ -53,6 +66,11 @@
public class BackupChainLog
{
+ /**
+ * Start for 1.1 version log will be stored relative paths.
+ */
+ protected static String VERSION_LOG_1_1 = "1.1";
+
protected static Log logger =
ExoLogger.getLogger("exo.jcr.component.ext.BackupChainLog");
public static final String PREFIX = "backup-";
@@ -79,6 +97,12 @@
private boolean finalized;
+ private WorkspaceEntry originalWorkspaceEntry;
+
+ private final String versionLog;
+
+ private File rootDir;
+
/**
* BackupChainLog constructor.
*
@@ -92,24 +116,30 @@
* Sting, FQN for incremental backup
* @param backupId
* String, the identifier of backup
+ * @param wEntry
+ * original workspace config
* @throws BackupOperationException
* will be generate the exception BackupOperationException
*/
public BackupChainLog(File logDir, BackupConfig config, String fullBackupType, String
incrementalBackupType,
- String backupId) throws BackupOperationException
+ String backupId, WorkspaceEntry wEntry, File rootDir) throws
BackupOperationException
{
try
{
this.finalized = false;
+ this.versionLog = VERSION_LOG_1_1;
this.log = new File(logDir.getCanonicalPath() + File.separator + (PREFIX +
backupId + SUFFIX));
+ this.rootDir = rootDir;
this.log.createNewFile();
this.backupId = backupId;
this.config = config;
this.jobEntries = new ArrayList<JobEntryInfo>();
+ this.originalWorkspaceEntry = wEntry;
// write config info here
logWriter = new LogWriter(log);
logWriter.write(config, fullBackupType, incrementalBackupType);
+ logWriter.writeWorkspaceEntry(originalWorkspaceEntry);
}
catch (IOException e)
{
@@ -123,6 +153,10 @@
{
throw new BackupOperationException(e);
}
+ catch (JsonException e)
+ {
+ throw new BackupOperationException(e);
+ }
}
/**
@@ -144,10 +178,12 @@
logReader.readLogFile();
logReader.jobEntrysNormalize();
+ this.versionLog = logReader.getVersionLog();
this.config = logReader.getBackupConfig();
this.startedTime = logReader.getBeginTime();
this.finishedTime = logReader.getEndTime();
this.jobEntries = logReader.getJobEntryInfoNormalizeList();
+ this.originalWorkspaceEntry = logReader.getOriginalWorkspaceEntry();
for (JobEntryInfo info : jobEntries)
{
@@ -178,6 +214,10 @@
{
throw new BackupOperationException(e);
}
+ catch (Exception e)
+ {
+ throw new BackupOperationException(e);
+ }
}
/**
@@ -197,7 +237,7 @@
info.setState(job.getState());
info.setURL(job.getStorageURL());
- logWriter.write(info);
+ logWriter.write(info, config);
}
catch (Exception e)
{
@@ -246,6 +286,33 @@
{
finalized = true;
logWriter.writeEndLog();
+
+ //copy backup chain log file in into Backupset files itself for portability (e.g.
on another server)
+ try
+ {
+ InputStream in = new FileInputStream(log);
+
+ File dest = new File(config.getBackupDir() + File.separator + log.getName());
+ if (!dest.exists())
+ {
+ OutputStream out = new FileOutputStream(dest);
+
+ byte[] buf = new byte[(int) (log.length())];
+ in.read(buf);
+
+ String sConfig = new String(buf, Constants.DEFAULT_ENCODING);
+ sConfig =
sConfig.replaceAll("<backup-dir>.+</backup-dir>",
"<backup-dir>.</backup-dir>");
+
+ out.write(sConfig.getBytes(Constants.DEFAULT_ENCODING));
+ in.close();
+ out.close();
+ }
+ }
+ catch (Exception e)
+ {
+ logger.error("Can't write log", e);
+ }
+
}
/**
@@ -309,6 +376,17 @@
return finishedTime;
}
+ /**
+ * Getting original workspace configuration
+ *
+ * @return WorkspaceEntry
+ * return the original workspace configuration
+ */
+ public WorkspaceEntry getOriginalWorkspaceEntry()
+ {
+ return originalWorkspaceEntry;
+ }
+
private class LogReader
{
protected Log logger =
ExoLogger.getLogger("exo.jcr.component.ext.LogReader");
@@ -322,15 +400,31 @@
private List<JobEntryInfo> jobEntries;
private List<JobEntryInfo> jobEntriesNormalize;
+
+ private WorkspaceEntry originalWorkspaceEntry;
+
+ private String version;
public LogReader(File logFile) throws FileNotFoundException, XMLStreamException,
FactoryConfigurationError
{
this.logFile = logFile;
jobEntries = new ArrayList<JobEntryInfo>();
- reader = XMLInputFactory.newInstance().createXMLStreamReader(new
FileInputStream(this.logFile));
+ reader =
+ XMLInputFactory.newInstance().createXMLStreamReader(new
FileInputStream(this.logFile),
+ Constants.DEFAULT_ENCODING);
}
+ public String getVersionLog()
+ {
+ return version;
+ }
+
+ public WorkspaceEntry getOriginalWorkspaceEntry()
+ {
+ return originalWorkspaceEntry;
+ }
+
public BackupConfig getBackupConfig()
{
return config;
@@ -356,7 +450,7 @@
return jobEntries.get(jobEntries.size() - 1).getDate();
}
- public void readLogFile() throws XMLStreamException, MalformedURLException,
ValueFormatException
+ public void readLogFile() throws Exception
{
boolean endDocument = false;
@@ -375,6 +469,14 @@
if (name.equals("job-entry-info"))
jobEntries.add(readJobEntryInfo());
+ if (name.equals("original-workspace-config"))
+ this.originalWorkspaceEntry = readWorkspaceEntry();
+
+ if (name.equals("version-log"))
+ {
+ this.version = readContent();
+ }
+
break;
case StartElement.END_DOCUMENT :
@@ -384,8 +486,38 @@
}
}
- private JobEntryInfo readJobEntryInfo() throws XMLStreamException,
MalformedURLException, ValueFormatException
+ private WorkspaceEntry readWorkspaceEntry() throws Exception
{
+ String jsonRepositoryEntry = reader.getElementText();
+
+ return (WorkspaceEntry) (getObject(WorkspaceEntry.class, jsonRepositoryEntry
+ .getBytes(Constants.DEFAULT_ENCODING)));
+ }
+
+ /**
+ * Will be created the Object from JSON binary data.
+ *
+ * @param cl
+ * Class
+ * @param data
+ * binary data (JSON)
+ * @return Object
+ * @throws Exception
+ * will be generated Exception
+ */
+ private Object getObject(Class cl, byte[] data) throws Exception
+ {
+ JsonHandler jsonHandler = new JsonDefaultHandler();
+ JsonParser jsonParser = new JsonParserImpl();
+ InputStream inputStream = new ByteArrayInputStream(data);
+ jsonParser.parse(inputStream, jsonHandler);
+ JsonValue jsonValue = jsonHandler.getJsonObject();
+
+ return new BeanBuilder().createObject(cl, jsonValue);
+ }
+
+ private JobEntryInfo readJobEntryInfo() throws XMLStreamException,
ValueFormatException, IOException
+ {
JobEntryInfo info = new JobEntryInfo();
boolean endJobEntryInfo = false;
@@ -406,8 +538,22 @@
info.setState(getState(readContent()));
if (name.equals("url"))
- info.setURL(new URL(readContent()));
+ {
+ if (version != null && version.equals(VERSION_LOG_1_1))
+ {
+ String path =
+ readContent().replace("file:",
+ "file:" +
config.getBackupDir().getCanonicalPath()
+ + File.separator);
+ info.setURL(new URL(path));
+ }
+ else
+ {
+ info.setURL(new URL(readContent()));
+ }
+ }
+
if (name.equals("date"))
info.setDate(JCRDateFormat.parse(readContent()));
@@ -457,7 +603,7 @@
return type;
}
- private BackupConfig readBackupConfig() throws XMLStreamException
+ private BackupConfig readBackupConfig() throws XMLStreamException, IOException
{
BackupConfig conf = new BackupConfig();
@@ -473,8 +619,27 @@
String name = reader.getLocalName();
if (name.equals("backup-dir"))
- conf.setBackupDir(new File(readContent()));
+ {
+ if (version != null && version.equals(VERSION_LOG_1_1))
+ {
+ String dir = readContent();
+ if (dir.equals("."))
+ {
+ String path = logFile.getParentFile().getCanonicalPath();
+ conf.setBackupDir(new File(path));
+ }
+ else
+ {
+ conf.setBackupDir(new File(dir));
+ }
+ }
+ else
+ {
+ conf.setBackupDir(new File(readContent()));
+ }
+ }
+
if (name.equals("repository"))
conf.setRepository(readContent());
@@ -546,15 +711,32 @@
{
this.logFile = logFile;
- writer = XMLOutputFactory.newInstance().createXMLStreamWriter(new
FileOutputStream(this.logFile));
+ writer =
+ XMLOutputFactory.newInstance().createXMLStreamWriter(new
FileOutputStream(this.logFile),
+ Constants.DEFAULT_ENCODING);
writer.writeStartDocument();
- writer.writeStartElement("backup-cain-log");
+ writer.writeStartElement("backup-chain-log");
+
+ writer.writeStartElement("version-log");
+ writer.writeCharacters(versionLog);
+ writer.writeEndElement();
+
writer.flush();
}
+ public void writeWorkspaceEntry(WorkspaceEntry originalWorkspaceEntry) throws
JsonException, XMLStreamException
+ {
+ JsonGeneratorImpl generatorImpl = new JsonGeneratorImpl();
+ JsonValue json = generatorImpl.createJsonObject(originalWorkspaceEntry);
+
+ writer.writeStartElement("original-workspace-config");
+ writer.writeCData(json.toString());
+ writer.writeEndElement();
+ }
+
public synchronized void write(BackupConfig config, String fullBackupType, String
incrementalBackupType)
- throws XMLStreamException
+ throws XMLStreamException, IOException
{
writer.writeStartElement("backup-config");
@@ -569,7 +751,14 @@
if (config.getBackupDir() != null)
{
writer.writeStartElement("backup-dir");
- writer.writeCharacters(config.getBackupDir().getAbsolutePath());
+
+ String path =
+ (isRootBackupManagerDir(logFile) ?
config.getBackupDir().getCanonicalPath() : config
+ .getBackupDir().getCanonicalPath()
+ .replace(logFile.getParentFile().getCanonicalPath(),
""));
+
+
+ writer.writeCharacters(path.equals("") ? "." : path);
writer.writeEndElement();
}
@@ -600,7 +789,7 @@
writer.flush();
}
- public synchronized void write(JobEntryInfo info) throws XMLStreamException
+ public synchronized void write(JobEntryInfo info, BackupConfig config) throws
XMLStreamException, IOException
{
writer.writeStartElement("job-entry-info");
@@ -613,7 +802,7 @@
writer.writeEndElement();
writer.writeStartElement("url");
- writer.writeCharacters(info.getURL().toString());
+ writer.writeCharacters(getRelativeUrl(info.getURL(), config.getBackupDir()));
writer.writeEndElement();
writer.writeStartElement("date");
@@ -625,6 +814,18 @@
writer.flush();
}
+ private String getRelativeUrl(URL url, File backupDir) throws IOException
+ {
+ String str = new File(url.getFile()).getCanonicalPath();
+
+ return url.getProtocol() + ":" +
str.replace(config.getBackupDir().getCanonicalPath() + File.separator, "");
+ }
+
+ private boolean isRootBackupManagerDir(File log) throws IOException
+ {
+ return
(log.getCanonicalFile().getParentFile().getCanonicalPath().equals(rootDir.getCanonicalPath()));
+ }
+
public synchronized void writeEndLog()
{
try
Added:
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/ExtendedBackupManager.java
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/ExtendedBackupManager.java
(rev 0)
+++
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/ExtendedBackupManager.java 2010-11-25
15:27:54 UTC (rev 3569)
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,
see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.ext.backup;
+
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date: 2010
+ *
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex
Reshetnyak</a>
+ * @version $Id: ExtendedBackupManager.java 3545 2010-11-24 15:35:31Z areshetnyak $
+ */
+public interface ExtendedBackupManager
+ extends BackupManager
+{
+
+ // TODO Will be uncommented after fix issue JCR-1054
+ // /**
+ // * Restore existing workspace. Previous data will be deleted.
+ // * For getting status of workspace restore can use
+ // * BackupManager.getLastRestore(String repositoryName, String workspaceName)
method
+ // * WorkspaceEntry for restore should be contains in BackupChainLog.
+ // *
+ // * @param workspaceBackupIdentifier
+ // * identifier to workspace backup.
+ // * @param asynchronous
+ // * if 'true' restore will be in asynchronous mode (i.e. in
separated thread)
+ // * @throws BackupOperationException
+ // * if backup operation exception occurred
+ // * @throws BackupConfigurationException
+ // * if configuration exception occurred
+ // */
+ // void restoreExistingWorkspace(String workspaceBackupIdentifier, boolean
asynchronous)
+ // throws BackupOperationException, BackupConfigurationException;
+ //
+ // /**
+ // * Restore existing repository. Previous data will be deleted.
+ // * For getting status of repository restore can use
+ // * BackupManager.getLastRestore(String repositoryName) method.
+ // * ReprositoryEntry for restore should be contains in BackupChainLog.
+ // *
+ // * @param repositoryBackupIdentifier
+ // * identifier to repository backup.
+ // * @param asynchronous
+ // * if 'true' restore will be in asynchronous mode (i.e. in
separated thread)
+ // * @throws BackupOperationException
+ // * if backup operation exception occurred
+ // * @throws BackupConfigurationException
+ // * if configuration exception occurred
+ // */
+ // void restoreExistingRepository(String repositoryBackupIdentifier, boolean
asynchronous)
+ // throws BackupOperationException, BackupConfigurationException;
+
+ /**
+ * WorkspaceEntry for restore should be contains in BackupChainLog.
+ *
+ * @param workspaceBackupIdentifier
+ * identifier to workspace backup.
+ * @param asynchronous
+ * if 'true' restore will be in asynchronous mode (i.e. in separated
thread)
+ * @throws BackupOperationException
+ * if backup operation exception occurred
+ * @throws BackupConfigurationException
+ * if configuration exception occurred
+ */
+ void restoreWorkspace(String workspaceBackupIdentifier, boolean asynchronous) throws
BackupOperationException,
+ BackupConfigurationException;
+
+ /**
+ * ReprositoryEntry for restore should be contains in BackupChainLog.
+ *
+ * @param repositoryBackupIdentifier
+ * identifier to repository backup.
+ * @param asynchronous
+ * if 'true' restore will be in asynchronous mode (i.e. in separated
thread)
+ * @throws BackupOperationException
+ * if backup operation exception occurred
+ * @throws BackupConfigurationException
+ * if configuration exception occurred
+ */
+ void restoreRepository(String repositoryBackupIdentifier, boolean asynchronous) throws
BackupOperationException,
+ BackupConfigurationException;
+}
Modified:
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChainLog.java
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChainLog.java 2010-11-25
15:11:40 UTC (rev 3568)
+++
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChainLog.java 2010-11-25
15:27:54 UTC (rev 3569)
@@ -16,18 +16,19 @@
*/
package org.exoplatform.services.jcr.ext.backup;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
-import javax.jcr.ValueFormatException;
import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
@@ -36,9 +37,19 @@
import javax.xml.stream.XMLStreamWriter;
import javax.xml.stream.events.StartElement;
+import org.exoplatform.services.jcr.config.RepositoryEntry;
+import org.exoplatform.services.jcr.impl.Constants;
import org.exoplatform.services.jcr.impl.util.JCRDateFormat;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
+import org.exoplatform.ws.frameworks.json.JsonHandler;
+import org.exoplatform.ws.frameworks.json.JsonParser;
+import org.exoplatform.ws.frameworks.json.impl.BeanBuilder;
+import org.exoplatform.ws.frameworks.json.impl.JsonDefaultHandler;
+import org.exoplatform.ws.frameworks.json.impl.JsonException;
+import org.exoplatform.ws.frameworks.json.impl.JsonGeneratorImpl;
+import org.exoplatform.ws.frameworks.json.impl.JsonParserImpl;
+import org.exoplatform.ws.frameworks.json.value.JsonValue;
/**
* Created by The eXo Platform SAS.
@@ -63,15 +74,22 @@
{
this.logFile = logFile;
- writer = XMLOutputFactory.newInstance().createXMLStreamWriter(new
FileOutputStream(this.logFile));
+ writer =
+ XMLOutputFactory.newInstance().createXMLStreamWriter(new
FileOutputStream(this.logFile),
+ Constants.DEFAULT_ENCODING);
writer.writeStartDocument();
writer.writeStartElement("repository-backup-chain-log");
- writer.flush();
+ writer.writeStartElement("version-log");
+ writer.writeCharacters(versionLog);
+ writer.writeEndElement();
+
writer.writeStartElement("start-time");
writer.writeCharacters(JCRDateFormat.format(startedTime));
writer.writeEndElement();
+
+ writer.flush();
}
public void writeSystemWorkspaceName(String wsName) throws XMLStreamException
@@ -82,14 +100,16 @@
writer.flush();
}
- public void writeBackupsPath(List<String> wsLogFilePathList) throws
XMLStreamException
+ public void writeBackupsPath(List<String> wsLogFilePathList,
RepositoryBackupConfig config)
+ throws XMLStreamException,
+ IOException
{
writer.writeStartElement("workspaces-backup-info");
for (String path : wsLogFilePathList)
{
writer.writeStartElement("url");
- writer.writeCharacters(path);
+ writer.writeCharacters(path.replace(config.getBackupDir().getCanonicalPath()
+ File.separator, ""));
writer.writeEndElement();
}
@@ -99,7 +119,7 @@
}
public synchronized void write(RepositoryBackupConfig config, String
fullBackupType, String incrementalBackupType)
- throws XMLStreamException
+ throws XMLStreamException, IOException
{
writer.writeStartElement("repository-backup-config");
@@ -118,7 +138,7 @@
if (config.getBackupDir() != null)
{
writer.writeStartElement("backup-dir");
- writer.writeCharacters(config.getBackupDir().getAbsolutePath());
+ writer.writeCharacters(config.getBackupDir().getCanonicalPath());
writer.writeEndElement();
}
@@ -159,6 +179,17 @@
logger.error("Can't write end log", e);
}
}
+
+ public synchronized void writeRepositoryEntry(RepositoryEntry rEntry) throws
JsonException, XMLStreamException
+ {
+
+ JsonGeneratorImpl generatorImpl = new JsonGeneratorImpl();
+ JsonValue json = generatorImpl.createJsonObject(rEntry);
+
+ writer.writeStartElement("original-repository-config");
+ writer.writeCData(json.toString());
+ writer.writeEndElement();
+ }
}
private class LogReader
@@ -169,13 +200,17 @@
private XMLStreamReader reader;
+ private String version;
+
public LogReader(File logFile) throws FileNotFoundException, XMLStreamException,
FactoryConfigurationError
{
this.logFile = logFile;
- reader = XMLInputFactory.newInstance().createXMLStreamReader(new
FileInputStream(logFile));
+ reader =
+ XMLInputFactory.newInstance().createXMLStreamReader(new
FileInputStream(logFile),
+ Constants.DEFAULT_ENCODING);
}
- public void readLogFile() throws XMLStreamException, MalformedURLException,
ValueFormatException
+ public void readLogFile() throws UnsupportedEncodingException, Exception
{
boolean endDocument = false;
@@ -206,6 +241,15 @@
if (name.equals("finish-time"))
finishedTime = JCRDateFormat.parse(readContent());
+ if (name.equals("original-repository-config"))
+ originalRepositoryEntry = readRepositoryEntry();
+
+ if (name.equals("version-log"))
+ {
+ this.version = readContent();
+ }
+
+
break;
case StartElement.END_DOCUMENT :
@@ -215,8 +259,38 @@
}
}
- private List<String> readWorkspaceBackupInfo() throws XMLStreamException
+ private RepositoryEntry readRepositoryEntry() throws UnsupportedEncodingException,
Exception
{
+ String jsonRepositoryEntry = reader.getElementText();
+
+ return (RepositoryEntry) (getObject(RepositoryEntry.class, jsonRepositoryEntry
+ .getBytes(Constants.DEFAULT_ENCODING)));
+ }
+
+ /**
+ * Will be created the Object from JSON binary data.
+ *
+ * @param cl
+ * Class
+ * @param data
+ * binary data (JSON)
+ * @return Object
+ * @throws Exception
+ * will be generated Exception
+ */
+ private Object getObject(Class cl, byte[] data) throws Exception
+ {
+ JsonHandler jsonHandler = new JsonDefaultHandler();
+ JsonParser jsonParser = new JsonParserImpl();
+ InputStream inputStream = new ByteArrayInputStream(data);
+ jsonParser.parse(inputStream, jsonHandler);
+ JsonValue jsonValue = jsonHandler.getJsonObject();
+
+ return new BeanBuilder().createObject(cl, jsonValue);
+ }
+
+ private List<String> readWorkspaceBackupInfo() throws XMLStreamException,
IOException
+ {
List<String> wsBackupInfo = new ArrayList<String>();
boolean endWorkspaceBackupInfo = false;
@@ -231,7 +305,17 @@
String name = reader.getLocalName();
if (name.equals("url"))
- wsBackupInfo.add(readContent());
+ {
+ if (version != null && version.equals(VERSION_LOG_1_1))
+ {
+ String path = config.getBackupDir().getCanonicalPath() +
File.separator + readContent();
+ wsBackupInfo.add(path);
+ }
+ else
+ {
+ wsBackupInfo.add(readContent());
+ }
+ }
break;
@@ -247,7 +331,7 @@
return wsBackupInfo;
}
- private BackupConfig readBackupConfig() throws XMLStreamException
+ private BackupConfig readBackupConfig() throws XMLStreamException, IOException
{
BackupConfig conf = new BackupConfig();
@@ -263,8 +347,27 @@
String name = reader.getLocalName();
if (name.equals("backup-dir"))
- conf.setBackupDir(new File(readContent()));
+ {
+ if (version != null && version.equals(VERSION_LOG_1_1))
+ {
+ String dir = readContent();
+ if (dir.equals("."))
+ {
+ String path = logFile.getParentFile().getCanonicalPath();
+ conf.setBackupDir(new File(path));
+ }
+ else
+ {
+ conf.setBackupDir(new File(dir));
+ }
+ }
+ else
+ {
+ conf.setBackupDir(new File(readContent()));
+ }
+ }
+
if (name.equals("backup-type"))
conf.setBackupType(Integer.valueOf(readContent()));
@@ -312,82 +415,19 @@
return content;
}
- private JobEntryInfo readJobEntryInfo() throws XMLStreamException,
MalformedURLException, ValueFormatException
+ public String getVersionLog()
{
- JobEntryInfo info = new JobEntryInfo();
-
- boolean endJobEntryInfo = false;
-
- while (!endJobEntryInfo)
- {
- int eventCode = reader.next();
- switch (eventCode)
- {
-
- case StartElement.START_ELEMENT :
- String name = reader.getLocalName();
-
- if (name.equals("type"))
- info.setType(getType(readContent()));
-
- if (name.equals("state"))
- info.setState(getState(readContent()));
-
- if (name.equals("url"))
- info.setURL(new URL(readContent()));
-
- if (name.equals("date"))
- info.setDate(JCRDateFormat.parse(readContent()));
-
- break;
-
- case StartElement.END_ELEMENT :
- String tagName = reader.getLocalName();
-
- if (tagName.equals("job-entry-info"))
- endJobEntryInfo = true;
- break;
- }
- }
-
- return info;
+ return version;
}
-
- private int getState(String content)
- {
- int state = -1;
-
- if (content.equals("FINISHED"))
- state = BackupJob.FINISHED;
-
- if (content.equals("STARTING"))
- state = BackupJob.STARTING;
-
- if (content.equals("WAITING"))
- state = BackupJob.WAITING;
-
- if (content.equals("WORKING"))
- state = BackupJob.WORKING;
-
- return state;
- }
-
- private int getType(String content)
- {
- int type = -1;
-
- if (content.equals("FULL"))
- type = BackupJob.FULL;
-
- if (content.equals("INCREMENTAL"))
- type = BackupJob.INCREMENTAL;
-
- return type;
- }
}
protected static Log logger =
ExoLogger.getLogger("exo.jcr.component.ext.BackupChainLog");
+ /**
+ * Start for 1.1 version log will be stored relative paths.
+ */
+ protected static String VERSION_LOG_1_1 = "1.1";
+
public static final String PREFIX = "repository-backup-";
private static final String SUFFIX = ".xml";
@@ -416,6 +456,10 @@
private String increnetalBackupType;
+ private RepositoryEntry originalRepositoryEntry;
+
+ private final String versionLog;
+
/**
* @param logDirectory
* @param config
@@ -423,15 +467,17 @@
* @param wsLogFilePathList
* @param backupId
* @param startTime
+ * @param rEntry
* @throws BackupOperationException
*/
public RepositoryBackupChainLog(File logDirectory, RepositoryBackupConfig config,
String fullBackupType,
String incrementalBackupType, String systemWorkspace, List<String>
wsLogFilePathList, String backupId,
- Calendar startTime) throws BackupOperationException
+ Calendar startTime, RepositoryEntry rEntry) throws BackupOperationException
{
try
{
this.finalized = false;
+ this.versionLog = VERSION_LOG_1_1;
this.log = new File(logDirectory.getCanonicalPath() + File.separator + (PREFIX +
backupId + SUFFIX));
this.log.createNewFile();
this.backupId = backupId;
@@ -439,11 +485,13 @@
this.startedTime = Calendar.getInstance();
this.fullBackupType = fullBackupType;
this.increnetalBackupType = incrementalBackupType;
+ this.originalRepositoryEntry = rEntry;
logWriter = new LogWriter(log);
logWriter.write(config, fullBackupType, incrementalBackupType);
logWriter.writeSystemWorkspaceName(systemWorkspace);
- logWriter.writeBackupsPath(wsLogFilePathList);
+ logWriter.writeBackupsPath(wsLogFilePathList, config);
+ logWriter.writeRepositoryEntry(rEntry);
this.workspaceBackupsInfo = wsLogFilePathList;
this.workspaceSystem = systemWorkspace;
@@ -460,6 +508,10 @@
{
throw new BackupOperationException("Can not create backup log ...",
e);
}
+ catch (JsonException e)
+ {
+ throw new BackupOperationException("Can not create backup log ...",
e);
+ }
}
/**
@@ -475,6 +527,7 @@
{
logReader = new LogReader(log);
logReader.readLogFile();
+ this.versionLog = logReader.getVersionLog();
}
catch (FileNotFoundException e)
{
@@ -486,21 +539,16 @@
throw new BackupOperationException(
"Can not read RepositoryBackupChainLog from file :" +
log.getAbsolutePath(), e);
}
- catch (FactoryConfigurationError e)
+ catch (UnsupportedEncodingException e)
{
throw new BackupOperationException(
"Can not read RepositoryBackupChainLog from file :" +
log.getAbsolutePath(), e);
}
- catch (MalformedURLException e)
+ catch (Exception e)
{
throw new BackupOperationException(
"Can not read RepositoryBackupChainLog from file :" +
log.getAbsolutePath(), e);
}
- catch (ValueFormatException e)
- {
- throw new BackupOperationException(
- "Can not read RepositoryBackupChainLog from file :" +
log.getAbsolutePath(), e);
- }
}
/**
@@ -563,6 +611,33 @@
finishedTime = Calendar.getInstance();
finalized = true;
logWriter.writeEndLog();
+
+ //copy backup chain log file in into Backupset files itself for portability
(e.g. on another server)
+ try
+ {
+ InputStream in = new FileInputStream(log);
+
+ File dest = new File(config.getBackupDir() + File.separator +
log.getName());
+ if (!dest.exists())
+ {
+ OutputStream out = new FileOutputStream(dest);
+
+ byte[] buf = new byte[(int) (log.length())];
+ in.read(buf);
+
+ String sConfig = new String(buf, Constants.DEFAULT_ENCODING);
+ sConfig =
sConfig.replaceAll("<backup-dir>.+</backup-dir>",
"<backup-dir>.</backup-dir>");
+
+ out.write(sConfig.getBytes(Constants.DEFAULT_ENCODING));
+
+ in.close();
+ out.close();
+ }
+ }
+ catch (Exception e)
+ {
+ logger.error("Can't write log", e);
+ }
}
}
@@ -599,4 +674,15 @@
return backupId;
}
+ /**
+ * Getting original repository configuration
+ *
+ * @return RepositoryEntry
+ * return the original repository configuration
+ */
+ public RepositoryEntry getOriginalRepositoryEntry()
+ {
+ return originalRepositoryEntry;
+ }
+
}
Added:
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/WorkspaceRestoreException.java
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/WorkspaceRestoreException.java
(rev 0)
+++
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/WorkspaceRestoreException.java 2010-11-25
15:27:54 UTC (rev 3569)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,
see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.ext.backup;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date: 2010
+ *
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex
Reshetnyak</a>
+ * @version $Id: WorkspaceRestoreException.java 3210 2010-09-28 12:01:50Z areshetnyak $
+ */
+public class WorkspaceRestoreException
+ extends BackupConfigurationException
+{
+
+ /**
+ * WorkspaceRestoreException constructor.
+ *
+ * @param message
+ * String, the exception message
+ */
+ public WorkspaceRestoreException(String message)
+ {
+ super(message);
+ }
+
+ /**
+ * WorkspaceRestoreException constructor.
+ *
+ * @param message
+ * String, the exception message
+ * @param e
+ * Throwable, the cause exception
+ */
+ public WorkspaceRestoreException(String message, Throwable e)
+ {
+ super(message, e);
+ }
+}
\ No newline at end of file
Modified:
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupChainImpl.java
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupChainImpl.java 2010-11-25
15:11:40 UTC (rev 3568)
+++
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupChainImpl.java 2010-11-25
15:27:54 UTC (rev 3569)
@@ -18,6 +18,18 @@
*/
package org.exoplatform.services.jcr.ext.backup.impl;
+import java.io.File;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.core.ManageableRepository;
import org.exoplatform.services.jcr.ext.backup.BackupChain;
import org.exoplatform.services.jcr.ext.backup.BackupChainLog;
@@ -30,17 +42,6 @@
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
-import java.io.File;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.Timer;
-import java.util.TimerTask;
-
/**
* Created by The eXo Platform SARL .<br/>
*
@@ -74,12 +75,16 @@
private Set<BackupJobListener> listeners = new
LinkedHashSet<BackupJobListener>();
public BackupChainImpl(BackupConfig config, File logDirectory, ManageableRepository
repository,
- String fullBackupType, String incrementalBackupType, String backupId) throws
BackupOperationException,
+ String fullBackupType, String incrementalBackupType, String backupId, File
rootDir)
+ throws BackupOperationException,
BackupConfigurationException
{
this.config = config;
this.jobs = new ArrayList<BackupJob>();
- this.chainLog = new BackupChainLog(logDirectory, config, fullBackupType,
incrementalBackupType, backupId);
+
+ this.chainLog =
+ new BackupChainLog(logDirectory, config, fullBackupType,
incrementalBackupType, backupId,
+ getWorkspaceEntry(config.getWorkspace(), repository), rootDir);
this.timeStamp = Calendar.getInstance();
this.backupId = backupId;
@@ -113,6 +118,29 @@
+ "_PeriodTimer_" + new
SimpleDateFormat("yyyyMMdd.HHmmss.SSS").format(new Date()), true);
}
+ private WorkspaceEntry getWorkspaceEntry(String workspace, ManageableRepository
repository)
+ throws BackupOperationException
+ {
+ WorkspaceEntry wEntry = null;
+
+ for (WorkspaceEntry entry : repository.getConfiguration().getWorkspaceEntries())
+ {
+ if (entry.getName().equals(workspace))
+ {
+ wEntry = entry;
+ break;
+ }
+ }
+
+ if (wEntry == null)
+ {
+ throw new BackupOperationException("Worksapce \"" + workspace +
"\" was not exsisted in repository \""
+ + repository.getConfiguration().getName() + "\".");
+ }
+
+ return wEntry;
+ }
+
/**
* Add all listeners to a given job. Used in startBackup() which itself is
synchronized.
*
Modified:
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java 2010-11-25
15:11:40 UTC (rev 3568)
+++
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java 2010-11-25
15:27:54 UTC (rev 3569)
@@ -66,10 +66,13 @@
import org.exoplatform.services.jcr.ext.backup.BackupJobListener;
import org.exoplatform.services.jcr.ext.backup.BackupManager;
import org.exoplatform.services.jcr.ext.backup.BackupOperationException;
+import org.exoplatform.services.jcr.ext.backup.ExtendedBackupManager;
import org.exoplatform.services.jcr.ext.backup.JobEntryInfo;
import org.exoplatform.services.jcr.ext.backup.RepositoryBackupChain;
import org.exoplatform.services.jcr.ext.backup.RepositoryBackupChainLog;
import org.exoplatform.services.jcr.ext.backup.RepositoryBackupConfig;
+import org.exoplatform.services.jcr.ext.backup.RepositoryRestoreExeption;
+import org.exoplatform.services.jcr.ext.backup.WorkspaceRestoreException;
import org.exoplatform.services.jcr.ext.common.SessionProvider;
import org.exoplatform.services.jcr.ext.registry.RegistryEntry;
import org.exoplatform.services.jcr.ext.registry.RegistryService;
@@ -98,7 +101,8 @@
* @version $Id: $
*/
-public class BackupManagerImpl implements BackupManager, Startable
+public class BackupManagerImpl
+ implements ExtendedBackupManager, Startable
{
protected static Log log =
ExoLogger.getLogger("exo.jcr.component.ext.BackupManagerImpl");
@@ -592,7 +596,7 @@
String reposytoryName = (repositoryName == null ? config.getRepository() :
repositoryName);
String workspaceName = workspaceEntry.getName();
- // ws should be registered not created
+ // ws should not exists.
if (!workspaceAlreadyExist(reposytoryName, workspaceName))
{
@@ -639,7 +643,7 @@
}
}
else
- throw new BackupConfigurationException("Workspace should exists " +
workspaceName);
+ throw new BackupConfigurationException("Workspace \"" +
workspaceName + "\" should not exists.");
}
private boolean workspaceAlreadyExist(String repository, String workspace) throws
RepositoryException,
@@ -680,8 +684,8 @@
validateBackupConfig(config);
BackupChain bchain =
- new BackupChainImpl(config, logsDirectory,
repoService.getRepository(config.getRepository()), fullBackupType,
- incrementalBackupType, IdGenerator.generate());
+ new BackupChainImpl(config, logsDirectory,
repoService.getRepository(config.getRepository()),
+ fullBackupType, incrementalBackupType, IdGenerator.generate(),
logsDirectory);
bchain.addListener(messagesListener);
bchain.addListener(jobListener);
@@ -1498,7 +1502,7 @@
RepositoryBackupChain repositoryBackupChain =
new RepositoryBackupChainImpl(config, logsDirectory, repository, fullBackupType,
incrementalBackupType,
- IdGenerator.generate());
+ IdGenerator.generate());
repositoryBackupChain.startBackup();
@@ -1553,4 +1557,142 @@
}
return null;
}
+
+ // TODO Will be uncommented after fix issue JCR-1054
+ // /**
+ // * {@inheritDoc}
+ // */
+ // public void restoreExistingRepository(String repositoryBackupIdentifier, boolean
asynchronous)
+ // throws BackupOperationException, BackupConfigurationException
+ // {
+ // RepositoryBackupChainLog backupChainLog = null;
+ //
+ // for (RepositoryBackupChainLog chainLog : getRepositoryBackupsLogs())
+ // {
+ // if (chainLog.getBackupId().equals(repositoryBackupIdentifier))
+ // {
+ // backupChainLog = chainLog;
+ // break;
+ // }
+ // }
+ //
+ // if (backupChainLog == null)
+ // {
+ // throw new BackupConfigurationException("Can not founf backup of
repository with id \""
+ // + repositoryBackupIdentifier + "\"");
+ // }
+ //
+ // this.restoreExistingRepository(backupChainLog,
backupChainLog.getOriginalRepositoryEntry(), asynchronous);
+ //
+ // }
+
+ // TODO Will be uncommented after fix issue JCR-1054
+ // /**
+ // * {@inheritDoc}
+ // */
+ // public void restoreExistingWorkspace(String workspaceBackupIdentifier, boolean
asynchronous)
+ // throws BackupOperationException, BackupConfigurationException
+ // {
+ // BackupChainLog backupChainLog = null;
+ //
+ // for (BackupChainLog chainLog : getBackupsLogs())
+ // {
+ // if (chainLog.getBackupId().equals(workspaceBackupIdentifier))
+ // {
+ // backupChainLog = chainLog;
+ // break;
+ // }
+ // }
+ //
+ // if (backupChainLog == null)
+ // {
+ // throw new BackupConfigurationException("Can not founf backup of
workspace with id \""
+ // + workspaceBackupIdentifier + "\"");
+ // }
+ //
+ // this.restoreExistingWorkspace(backupChainLog,
backupChainLog.getBackupConfig().getRepository(), backupChainLog
+ // .getOriginalWorkspaceEntry(), asynchronous);
+ //
+ // }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void restoreRepository(String repositoryBackupIdentifier, boolean
asynchronous)
+ throws BackupOperationException, BackupConfigurationException
+ {
+ RepositoryBackupChainLog backupChainLog = null;
+
+ for (RepositoryBackupChainLog chainLog : getRepositoryBackupsLogs())
+ {
+ if (chainLog.getBackupId().equals(repositoryBackupIdentifier))
+ {
+ backupChainLog = chainLog;
+ break;
+ }
+ }
+
+ if (backupChainLog == null)
+ {
+ throw new BackupConfigurationException("Can not founf backup of repository
with id \""
+ + repositoryBackupIdentifier + "\"");
+ }
+
+ try
+ {
+ this.restore(backupChainLog, backupChainLog.getOriginalRepositoryEntry(),
asynchronous);
+ }
+ catch (RepositoryException e)
+ {
+ throw new RepositoryRestoreExeption("Repository \"" +
backupChainLog.getOriginalRepositoryEntry().getName()
+ + "\" was not restored", e);
+ }
+ catch (RepositoryConfigurationException e)
+ {
+ throw new RepositoryRestoreExeption("Repository \"" +
backupChainLog.getOriginalRepositoryEntry().getName()
+ + "\" was not restored", e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void restoreWorkspace(String workspaceBackupIdentifier, boolean asynchronous)
+ throws BackupOperationException, BackupConfigurationException
+ {
+ BackupChainLog backupChainLog = null;
+
+ for (BackupChainLog chainLog : getBackupsLogs())
+ {
+ if (chainLog.getBackupId().equals(workspaceBackupIdentifier))
+ {
+ backupChainLog = chainLog;
+ break;
+ }
+ }
+
+ if (backupChainLog == null)
+ {
+ throw new BackupConfigurationException("Can not founf backup of workspace
with id \""
+ + workspaceBackupIdentifier + "\"");
+ }
+
+ try
+ {
+ this.restore(backupChainLog, backupChainLog.getBackupConfig().getRepository(),
backupChainLog
+ .getOriginalWorkspaceEntry(), asynchronous);
+ }
+ catch (RepositoryException e)
+ {
+ throw new WorkspaceRestoreException("Workapce \"" +
backupChainLog.getOriginalWorkspaceEntry().getName()
+ + "\" was not restored in repository \"" +
backupChainLog.getBackupConfig().getRepository() + "\"", e);
+ }
+ catch (RepositoryConfigurationException e)
+ {
+
+ throw new WorkspaceRestoreException("Workapce \"" +
backupChainLog.getOriginalWorkspaceEntry().getName()
+ + "\" was not restored in repository \"" +
backupChainLog.getBackupConfig().getRepository() + "\"", e);
+ }
+
+ }
}
Modified:
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/RepositoryBackupChainImpl.java
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/RepositoryBackupChainImpl.java 2010-11-25
15:11:40 UTC (rev 3568)
+++
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/RepositoryBackupChainImpl.java 2010-11-25
15:27:54 UTC (rev 3569)
@@ -68,7 +68,8 @@
private int state;
public RepositoryBackupChainImpl(RepositoryBackupConfig config, File logDirectory,
ManageableRepository repository,
- String fullBackupType, String incrementalBackupType, String
repositoryBackupId) throws BackupOperationException,
+ String fullBackupType, String incrementalBackupType, String
repositoryBackupId)
+ throws BackupOperationException,
BackupConfigurationException
{
this.config = config;
@@ -89,8 +90,8 @@
wsBackupConfig.setIncrementalJobPeriod(config.getIncrementalJobPeriod());
BackupChain bchain =
- new BackupChainImpl(wsBackupConfig, config.getBackupDir(), repository,
- fullBackupType, incrementalBackupType, IdGenerator.generate());
+ new BackupChainImpl(wsBackupConfig, config.getBackupDir(), repository,
fullBackupType,
+ incrementalBackupType, IdGenerator.generate(), logDirectory);
wsLogFilePathList.add(bchain.getLogFilePath());
workspaceBackups.add(bchain);
@@ -103,7 +104,8 @@
repository.getConfiguration().getSystemWorkspaceName(),
wsLogFilePathList,
this.repositoryBackupId,
- startTime);
+ startTime,
+
repository.getConfiguration());
state = INITIALIZED;
}
Modified:
jcr/branches/1.12.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupTestCase.java
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupTestCase.java 2010-11-25
15:11:40 UTC (rev 3568)
+++
jcr/branches/1.12.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupTestCase.java 2010-11-25
15:27:54 UTC (rev 3569)
@@ -52,7 +52,8 @@
* @author <a href="mailto:peter.nedonosko@exoplatform.com.ua">Peter
Nedonosko</a>
* @version $Id: AbstractBackupTestCase.java 760 2008-02-07 15:08:07Z pnedonosko $
*/
-public class AbstractBackupTestCase extends BaseStandaloneTest
+public class AbstractBackupTestCase
+ extends BaseStandaloneTest
{
protected SessionImpl ws1Session;
@@ -63,7 +64,24 @@
protected BackupManager backup;
- class LogFilter implements FileFilter
+ // TODO Will be uncommented after fix issue JCR-1054
+ // /**
+ // * Database cleaner.
+ // */
+ // private DBCleanerService dbCleanerService = new DBCleanerService();
+ //
+ // /**
+ // * Value storage cleaner.
+ // */
+ // private ValueStorageCleanHelper valueStorageCleanHelper = new
ValueStorageCleanHelper();
+ //
+ // /**
+ // * Index storage cleaner.
+ // */
+ // private IndexCleanHelper indexCleanHelper = new IndexCleanHelper();
+
+ class LogFilter
+ implements FileFilter
{
public boolean accept(File pathname)
@@ -94,7 +112,7 @@
ws1TestRoot = ws1Session.getRootNode().addNode("backupTest");
ws1Session.save();
addContent(ws1TestRoot, 1, 10, 1);
-
+
}
else
{
@@ -106,7 +124,7 @@
}
// ws2
- ws2Session = (SessionImpl)repository.login(credentials, "ws2");
+ ws2Session = (SessionImpl) repository.login(credentials, "ws2");
}
@Override
@@ -115,17 +133,24 @@
for (String wsName : repository.getWorkspaceNames())
{
- if ("ws1".equals(wsName))
+ try
{
- ws1Session = (SessionImpl) repository.login(credentials, "ws1");
- ws1Session.getRootNode().getNode("backupTest").remove();
- ws1Session.save();
+ if ("ws1".equals(wsName))
+ {
+ ws1Session = (SessionImpl) repository.login(credentials,
"ws1");
+ ws1Session.getRootNode().getNode("backupTest").remove();
+ ws1Session.save();
+ }
+ else
+ {
+ SessionImpl ws = (SessionImpl) repository.login(credentials, wsName);
+ ws.getRootNode().getNode("backupTest").remove();
+ ws.save();
+ }
}
- else
+ catch (PathNotFoundException e)
{
- SessionImpl ws = (SessionImpl)repository.login(credentials, wsName);
- ws.getRootNode().getNode("backupTest").remove();
- ws.save();
+ //skip
}
}
@@ -134,13 +159,13 @@
protected WorkspaceEntry makeWorkspaceEntry(String name, String sourceName)
{
- WorkspaceEntry ws1e =
(WorkspaceEntry)ws1Session.getContainer().getComponentInstanceOfType(WorkspaceEntry.class);
+ WorkspaceEntry ws1e = (WorkspaceEntry)
ws1Session.getContainer().getComponentInstanceOfType(WorkspaceEntry.class);
WorkspaceEntry ws1back = new WorkspaceEntry();
ws1back.setName(name);
// RepositoryContainer rcontainer = (RepositoryContainer)
// container.getComponentInstanceOfType(RepositoryContainer.class);
- ws1back.setUniqueName(((RepositoryImpl)ws1Session.getRepository()).getName() +
"_" + ws1back.getName()); // EXOMAN
+ ws1back.setUniqueName(((RepositoryImpl) ws1Session.getRepository()).getName() +
"_" + ws1back.getName()); // EXOMAN
ws1back.setAccessManager(ws1e.getAccessManager());
ws1back.setCache(ws1e.getCache());
@@ -173,45 +198,49 @@
}
ContainerEntry ce =
- new
ContainerEntry("org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer",
params);
+ new
ContainerEntry("org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer",
params);
ws1back.setContainer(ce);
return ws1back;
}
-
- protected RepositoryEntry makeRepositoryEntry(String repoName, RepositoryEntry
baseRepoEntry, String sourceName, Map<String, String> workspaceMapping)
+
+ protected RepositoryEntry makeRepositoryEntry(String repoName, RepositoryEntry
baseRepoEntry, String sourceName,
+ Map<String, String> workspaceMapping)
{
ArrayList<WorkspaceEntry> wsEntries = new ArrayList<WorkspaceEntry>();
-
+
for (WorkspaceEntry wsEntry : baseRepoEntry.getWorkspaceEntries())
{
- String newWorkspaceName = wsEntry.getName();
+ String newWorkspaceName = wsEntry.getName();
if (workspaceMapping != null)
{
newWorkspaceName = workspaceMapping.get(wsEntry.getName());
}
-
+
WorkspaceEntry newWSEntry = makeWorkspaceEntry(wsEntry, newWorkspaceName,
repoName, sourceName);
-
+
wsEntries.add(newWSEntry);
}
-
+
RepositoryEntry newRepositoryEntry = new RepositoryEntry();
-
- newRepositoryEntry.setSystemWorkspaceName(workspaceMapping == null ?
baseRepoEntry.getSystemWorkspaceName() :
workspaceMapping.get(baseRepoEntry.getSystemWorkspaceName()));
+
+ newRepositoryEntry.setSystemWorkspaceName(workspaceMapping == null ?
baseRepoEntry.getSystemWorkspaceName()
+ : workspaceMapping.get(baseRepoEntry.getSystemWorkspaceName()));
newRepositoryEntry.setAccessControl(baseRepoEntry.getAccessControl());
newRepositoryEntry.setAuthenticationPolicy(baseRepoEntry.getAuthenticationPolicy());
- newRepositoryEntry.setDefaultWorkspaceName(workspaceMapping == null ?
baseRepoEntry.getDefaultWorkspaceName() :
workspaceMapping.get(baseRepoEntry.getDefaultWorkspaceName()));
+ newRepositoryEntry.setDefaultWorkspaceName(workspaceMapping == null ?
baseRepoEntry.getDefaultWorkspaceName()
+ : workspaceMapping.get(baseRepoEntry.getDefaultWorkspaceName()));
newRepositoryEntry.setName(repoName);
newRepositoryEntry.setSecurityDomain(baseRepoEntry.getSecurityDomain());
newRepositoryEntry.setSessionTimeOut(baseRepoEntry.getSessionTimeOut());
-
+
newRepositoryEntry.setWorkspaceEntries(wsEntries);
-
+
return newRepositoryEntry;
}
-
- protected WorkspaceEntry makeWorkspaceEntry(WorkspaceEntry baseWorkspaceEntry, String
wsName, String repoName, String sourceName)
+
+ protected WorkspaceEntry makeWorkspaceEntry(WorkspaceEntry baseWorkspaceEntry, String
wsName, String repoName,
+ String sourceName)
{
WorkspaceEntry ws1back = new WorkspaceEntry();
ws1back.setName(wsName);
@@ -240,7 +269,7 @@
if (newp.getName().equals("source-name"))
newp.setValue(sourceName);
else if (newp.getName().equals("swap-directory"))
- newp.setValue("target/temp/swap/" + repoName + "_" +
wsName);
+ newp.setValue("target/temp/swap/" + repoName + "_" +
wsName);
else if (newp.getName().equals("multi-db"))
newp.setValue("false");
@@ -248,18 +277,19 @@
}
ContainerEntry ce =
- new
ContainerEntry("org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer",
params);
+ new
ContainerEntry("org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer",
params);
ws1back.setContainer(ce);
return ws1back;
}
protected void restoreAndCheck(String workspaceName, String datasourceName, String
backupLogFilePath, File backDir,
- int startIndex, int stopIndex) throws RepositoryConfigurationException,
RepositoryException,
- BackupOperationException, BackupConfigurationException
+ int startIndex, int stopIndex) throws RepositoryConfigurationException,
RepositoryException,
+ BackupOperationException, BackupConfigurationException
{
// restore
- RepositoryEntry re =
(RepositoryEntry)ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
+ RepositoryEntry re =
+ (RepositoryEntry)
ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
WorkspaceEntry ws1back = makeWorkspaceEntry(workspaceName, datasourceName);
repository.configWorkspace(ws1back);
@@ -274,12 +304,12 @@
SessionImpl back1 = null;
try
{
- back1 = (SessionImpl)repository.login(credentials, ws1back.getName());
+ back1 = (SessionImpl) repository.login(credentials, ws1back.getName());
Node ws1backTestRoot = back1.getRootNode().getNode("backupTest");
for (int i = startIndex; i < stopIndex; i++)
{
assertEquals("Restored content should be same",
"property-" + i, ws1backTestRoot.getNode("node_" + i)
- .getProperty("exo:data").getString());
+ .getProperty("exo:data").getString());
}
}
catch (Exception e)
@@ -298,8 +328,8 @@
}
protected void addContent(Node node, int startIndex, int stopIndex, long sleepTime)
throws ValueFormatException,
- VersionException, LockException, ConstraintViolationException, ItemExistsException,
PathNotFoundException,
- RepositoryException, InterruptedException
+ VersionException, LockException, ConstraintViolationException,
ItemExistsException, PathNotFoundException,
+ RepositoryException, InterruptedException
{
for (int i = startIndex; i <= stopIndex; i++)
{
Modified:
jcr/branches/1.12.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java 2010-11-25
15:11:40 UTC (rev 3568)
+++
jcr/branches/1.12.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java 2010-11-25
15:27:54 UTC (rev 3569)
@@ -18,14 +18,6 @@
*/
package org.exoplatform.services.jcr.ext.backup;
-import org.apache.commons.collections.map.HashedMap;
-import org.exoplatform.services.jcr.config.RepositoryEntry;
-import org.exoplatform.services.jcr.config.WorkspaceEntry;
-import org.exoplatform.services.jcr.core.ManageableRepository;
-import org.exoplatform.services.jcr.ext.backup.impl.JobRepositoryRestore;
-import org.exoplatform.services.jcr.ext.backup.impl.JobWorkspaceRestore;
-import org.exoplatform.services.jcr.impl.core.SessionImpl;
-
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -36,6 +28,15 @@
import javax.jcr.RepositoryException;
import javax.jcr.lock.Lock;
+import org.apache.commons.collections.map.HashedMap;
+import org.exoplatform.services.jcr.config.RepositoryEntry;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.core.ManageableRepository;
+import org.exoplatform.services.jcr.ext.backup.impl.JobRepositoryRestore;
+import org.exoplatform.services.jcr.ext.backup.impl.JobWorkspaceRestore;
+import org.exoplatform.services.jcr.impl.core.SessionImpl;
+
+
/**
* Created by The eXo Platform SAS.
* Author : Peter Nedonosko peter.nedonosko(a)exoplatform.com.ua
@@ -48,74 +49,74 @@
{
public void testFullBackupRestore() throws Exception
- {
- // backup
- File backDir = new File("target/backup/ws1");
- backDir.mkdirs();
+ {
+ // backup
+ File backDir = new File("target/backup/ws1");
+ backDir.mkdirs();
- BackupConfig config = new BackupConfig();
- config.setRepository(repository.getName());
- config.setWorkspace("ws1");
- config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
+ BackupConfig config = new BackupConfig();
+ config.setRepository(repository.getName());
+ config.setWorkspace("ws1");
+ config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
- config.setBackupDir(backDir);
+ config.setBackupDir(backDir);
- backup.startBackup(config);
+ backup.startBackup(config);
- BackupChain bch = backup.findBackup(repository.getName(), "ws1");
+ BackupChain bch = backup.findBackup(repository.getName(), "ws1");
- // wait till full backup will be stopped
- while (bch.getFullBackupState() != BackupJob.FINISHED)
- {
- Thread.yield();
- Thread.sleep(50);
- }
+ // wait till full backup will be stopped
+ while (bch.getFullBackupState() != BackupJob.FINISHED)
+ {
+ Thread.yield();
+ Thread.sleep(50);
+ }
- // stop fullBackup
+ // stop fullBackup
- if (bch != null)
- backup.stopBackup(bch);
- else
- fail("Can't get fullBackup chain");
+ if (bch != null)
+ backup.stopBackup(bch);
+ else
+ fail("Can't get fullBackup chain");
- // restore
- RepositoryEntry re =
(RepositoryEntry)ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
- WorkspaceEntry ws1back = makeWorkspaceEntry("ws1back",
"jdbcjcr_backup_only_use_1");
+ // restore
+ RepositoryEntry re =
(RepositoryEntry)ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
+ WorkspaceEntry ws1back = makeWorkspaceEntry("ws1back",
"jdbcjcr_backup_only_use_1");
- // BackupChainLog bchLog = new BackupChainLog(backDir, rconfig);
- File backLog = new File(bch.getLogFilePath());
- if (backLog.exists())
- {
- BackupChainLog bchLog = new BackupChainLog(backLog);
+ // BackupChainLog bchLog = new BackupChainLog(backDir, rconfig);
+ File backLog = new File(bch.getLogFilePath());
+ if (backLog.exists())
+ {
+ BackupChainLog bchLog = new BackupChainLog(backLog);
- assertNotNull(bchLog.getStartedTime());
- assertNotNull(bchLog.getFinishedTime());
+ assertNotNull(bchLog.getStartedTime());
+ assertNotNull(bchLog.getFinishedTime());
- backup.restore(bchLog, re.getName(), ws1back, false);
+ backup.restore(bchLog, re.getName(), ws1back, false);
- // check
- SessionImpl back1 = null;
- try
- {
- back1 = (SessionImpl)repository.login(credentials, "ws1back");
- Node ws1backTestRoot = back1.getRootNode().getNode("backupTest");
- assertEquals("Restored content should be same",
"property-5", ws1backTestRoot.getNode("node_5")
- .getProperty("exo:data").getString());
+ // check
+ SessionImpl back1 = null;
+ try
+ {
+ back1 = (SessionImpl)repository.login(credentials, "ws1back");
+ Node ws1backTestRoot =
back1.getRootNode().getNode("backupTest");
+ assertEquals("Restored content should be same",
"property-5", ws1backTestRoot.getNode("node_5")
+ .getProperty("exo:data").getString());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ finally
+ {
+ if (back1 != null)
+ back1.logout();
+ }
}
- catch (Exception e)
- {
- e.printStackTrace();
- fail(e.getMessage());
- }
- finally
- {
- if (back1 != null)
- back1.logout();
- }
+ else
+ fail("There are no backup files in " + backDir.getAbsolutePath());
}
- else
- fail("There are no backup files in " + backDir.getAbsolutePath());
- }
public void testIncrementalBackupRestore() throws Exception
{
@@ -1221,4 +1222,288 @@
else
fail("There are no backup files in " + backDir.getAbsolutePath());
}
+
+ // TODO Will be uncommented after fix issue JCR-1054
+ /*public void testExistedWorkspaceRestoreWithConfig() throws Exception
+ {
+ // backup
+ File backDir = new File("target/backup/ws1");
+ backDir.mkdirs();
+
+ BackupConfig config = new BackupConfig();
+ config.setRepository(repository.getName());
+ config.setWorkspace("ws1");
+ config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
+
+ config.setBackupDir(backDir);
+
+ backup.startBackup(config);
+
+ BackupChain bch = backup.findBackup(repository.getName(), "ws1");
+
+ // wait till full backup will be stopped
+ while (bch.getFullBackupState() != BackupJob.FINISHED)
+ {
+ Thread.yield();
+ Thread.sleep(50);
+ }
+
+ // stop fullBackup
+ if (bch != null)
+ backup.stopBackup(bch);
+ else
+ fail("Can't get fullBackup chain");
+
+ super.tearDown();
+
+ File backLog = new File(bch.getLogFilePath());
+ if (backLog.exists())
+ {
+ BackupChainLog bchLog = new BackupChainLog(backLog);
+
+ assertNotNull(bchLog.getStartedTime());
+ assertNotNull(bchLog.getFinishedTime());
+
+ backup.restoreExistingWorkspace(bchLog.getBackupId(), false);
+
+ // check
+ SessionImpl back1 = null;
+ try
+ {
+ back1 = (SessionImpl) repository.login(credentials, "ws1");
+ Node ws1backTestRoot = back1.getRootNode().getNode("backupTest");
+ assertEquals("Restored content should be same",
"property-5", ws1backTestRoot.getNode("node_5")
+ .getProperty("exo:data").getString());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ finally
+ {
+ if (back1 != null)
+ back1.logout();
+ }
+ }
+ else
+ fail("There are no backup files in " + backDir.getAbsolutePath());
+ }
+
+ public void testExistedRepositoryRestoreWithConfig() throws Exception
+ {
+ // backup
+ File backDir = new File("target/backup/db1");
+ backDir.mkdirs();
+
+ RepositoryBackupConfig config = new RepositoryBackupConfig();
+ String repoName = repository.getName();
+ config.setRepository(repoName);
+ config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
+
+ config.setBackupDir(backDir);
+
+ backup.startBackup(config);
+
+ RepositoryBackupChain bch = backup.findRepositoryBackup(repository.getName());
+
+ // wait till full backup will be stopped
+ while (bch.getState() != RepositoryBackupChain.FINISHED)
+ {
+ Thread.yield();
+ Thread.sleep(50);
+ }
+
+ // stop fullBackup
+ backup.stopBackup(bch);
+
+ // check
+ super.tearDown();
+
+ // restore
+ File backLog = new File(bch.getLogFilePath());
+ if (backLog.exists())
+ {
+ RepositoryBackupChainLog bchLog = new RepositoryBackupChainLog(backLog);
+
+ assertNotNull(bchLog.getStartedTime());
+ assertNotNull(bchLog.getFinishedTime());
+
+ backup.restoreExistingRepository(bchLog.getBackupId(), false);
+
+ assertEquals(JobWorkspaceRestore.RESTORE_SUCCESSFUL,
backup.getLastRepositoryRestore(repoName)
+ .getStateRestore());
+
+ // check
+ ManageableRepository restoredRepository =
repositoryService.getRepository(repoName);
+
+ for (String wsName : restoredRepository.getWorkspaceNames())
+ {
+ SessionImpl back1 = null;
+ try
+ {
+ back1 = (SessionImpl) restoredRepository.login(credentials, wsName);
+ Node ws1backTestRoot =
back1.getRootNode().getNode("backupTest");
+ assertEquals("Restored content should be same",
"property-5", ws1backTestRoot.getNode("node_5")
+ .getProperty("exo:data").getString());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ finally
+ {
+ if (back1 != null)
+ back1.logout();
+ }
+ }
+ }
+ else
+ fail("There are no backup files in " + backDir.getAbsolutePath());
+ }
+
+ public void testWorkspaceRestoreWithConfig() throws Exception
+ {
+ // backup
+ File backDir = new File("target/backup/ws1");
+ backDir.mkdirs();
+
+ BackupConfig config = new BackupConfig();
+ config.setRepository(repository.getName());
+ config.setWorkspace("ws1");
+ config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
+
+ config.setBackupDir(backDir);
+
+ backup.startBackup(config);
+
+ BackupChain bch = backup.findBackup(repository.getName(), "ws1");
+
+ // wait till full backup will be stopped
+ while (bch.getFullBackupState() != BackupJob.FINISHED)
+ {
+ Thread.yield();
+ Thread.sleep(50);
+ }
+
+ // stop fullBackup
+
+ if (bch != null)
+ backup.stopBackup(bch);
+ else
+ fail("Can't get fullBackup chain");
+
+ //TODO
+ super.tearDown();
+ removeWorkspaceFully(repository.getName(), "ws1");
+
+ File backLog = new File(bch.getLogFilePath());
+ if (backLog.exists())
+ {
+ BackupChainLog bchLog = new BackupChainLog(backLog);
+
+ assertNotNull(bchLog.getStartedTime());
+ assertNotNull(bchLog.getFinishedTime());
+
+ backup.restoreWorkspace(bchLog.getBackupId(), false);
+
+ // check
+ SessionImpl back1 = null;
+ try
+ {
+ back1 = (SessionImpl) repository.login(credentials, "ws1");
+ Node ws1backTestRoot = back1.getRootNode().getNode("backupTest");
+ assertEquals("Restored content should be same",
"property-5", ws1backTestRoot.getNode("node_5")
+ .getProperty("exo:data").getString());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ finally
+ {
+ if (back1 != null)
+ back1.logout();
+ }
+ }
+ else
+ fail("There are no backup files in " + backDir.getAbsolutePath());
+ }
+
+ public void testRepositoryRestoreWithConfig() throws Exception
+ {
+ // backup
+ File backDir = new File("target/backup");
+ backDir.mkdirs();
+
+ RepositoryBackupConfig config = new RepositoryBackupConfig();
+ String repoName = repository.getName();
+ config.setRepository(repoName);
+ config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
+
+ config.setBackupDir(backDir);
+
+ backup.startBackup(config);
+
+ RepositoryBackupChain bch = backup.findRepositoryBackup(repository.getName());
+
+ // wait till full backup will be stopped
+ while (bch.getState() != RepositoryBackupChain.FINISHED)
+ {
+ Thread.yield();
+ Thread.sleep(50);
+ }
+
+ // stop fullBackup
+
+ backup.stopBackup(bch);
+
+ //TODO
+ super.tearDown();
+ removeRepositoryFully(repository.getName());
+
+ // restore
+ File backLog = new File(bch.getLogFilePath());
+ if (backLog.exists())
+ {
+ RepositoryBackupChainLog bchLog = new RepositoryBackupChainLog(backLog);
+
+ assertNotNull(bchLog.getStartedTime());
+ assertNotNull(bchLog.getFinishedTime());
+
+ backup.restoreRepository(bchLog.getBackupId(), false);
+
+ assertEquals(JobWorkspaceRestore.RESTORE_SUCCESSFUL,
backup.getLastRepositoryRestore(repoName)
+ .getStateRestore());
+
+ // check
+ ManageableRepository restoredRepository =
repositoryService.getRepository(repoName);
+
+ for (String wsName : restoredRepository.getWorkspaceNames())
+ {
+ SessionImpl back1 = null;
+ try
+ {
+ back1 = (SessionImpl) restoredRepository.login(credentials, wsName);
+ Node ws1backTestRoot =
back1.getRootNode().getNode("backupTest");
+ assertEquals("Restored content should be same",
"property-5", ws1backTestRoot.getNode("node_5")
+ .getProperty("exo:data").getString());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ finally
+ {
+ if (back1 != null)
+ back1.logout();
+ }
+ }
+ }
+ else
+ fail("There are no backup files in " + backDir.getAbsolutePath());
+ }*/
}