* {@inheritDoc}
*/
public void backup(final File storageDir) throws BackupException
{
LOG.info("Start to backup value storage of the workspace '"+containerConfig.containerName+"'");
ObjectWriter backupInfo = null;
try
{
backupInfo =
new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(new File(storageDir,
"JDBCWorkspaceDataContainer.info")));
backupInfo.writeString(containerConfig.containerName);
backupInfo.writeString(containerConfig.dbStructureType.toString());
Map<String, String> scripts = new HashMap<String, String>();
String itemTable = DBInitializerHelper.getItemTableName(containerConfig);
String valueTable = DBInitializerHelper.getValueTableName(containerConfig);
String refTable = DBInitializerHelper.getRefTableName(containerConfig);
backupInfo.writeString(itemTable);
backupInfo.writeString(valueTable);
backupInfo.writeString(refTable);
if (containerConfig.dbStructureType.isMultiDatabase())
{
scripts
.put(itemTable, "select * from " + itemTable + " where NAME <> '" + Constants.ROOT_PARENT_NAME + "'");
scripts.put(valueTable, "select * from " + valueTable);
scripts.put(refTable, "select * from " + refTable);
}
else
{
scripts.put(itemTable, "select * from " + itemTable + " where CONTAINER_NAME='"
+ containerConfig.containerName + "'");
scripts.put(valueTable, "select V.* from " + valueTable + " V, " + itemTable
+ " I where I.ID=V.PROPERTY_ID and I.CONTAINER_NAME='" + containerConfig.containerName + "'");
scripts.put(refTable, "select R.* from " + refTable + " R, " + itemTable
+ " I where I.ID=R.PROPERTY_ID and I.CONTAINER_NAME='" + containerConfig.containerName + "'");
}
// using existing DataSource to get a JDBC Connection.
Connection jdbcConn = connFactory.getJdbcConnection();
DBBackup.backup(storageDir, jdbcConn, scripts);
// backup value storage
if (wsConfig.getContainer().getValueStorages() != null)
{
SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Void>()
{
public Void run() throws RepositoryConfigurationException, IOException
{
for (ValueStorageEntry valueStorage : wsConfig.getContainer().getValueStorages())
{
File srcDir = new File(valueStorage.getParameterValue(FileValueStorage.PATH));
if (!srcDir.exists())
{
throw new IOException("Can't backup value storage. Directory " + srcDir.getName()
+ " doesn't exists");
}
else
{
File zipFile = new File(storageDir, "values-" + valueStorage.getId() + ".zip");
DirectoryHelper.compressDirectory(srcDir, zipFile);
}
}
return null;
}
});
}
}
catch (IOException e)
{
throw new BackupException(e);
}
catch (RepositoryException e)
{
throw new BackupException(e);
}
catch (PrivilegedActionException e)
{
throw new BackupException(e);
}
finally
{
if (backupInfo != null)
{
try
{
backupInfo.close();
}
catch (IOException e)
{
throw new BackupException(e);
}