// Write out the repository metadata document (which may have not changed) ...
NodeKey metadataKey = repositoryCache.getRepositoryMetadataDocumentKey();
SchematicEntry entry = documentStore.get(metadataKey.toString());
writeToContentArea(entry);
} catch (Exception e) {
I18n msg = JcrI18n.problemObtainingDocumentsToBackup;
this.problems.addError(msg, repositoryName(), backupLocation(), e.getMessage());
} finally {
// Now that we're done with the backup, unregister the listener ...
try {
repositoryCache.changeBus().unregister(observer);
} finally {
// Now stop the worker that is writing changed documents ...
continueWritingChangedDocuments.set(false);
// Shutdown the worker (gracefully, which will complete if 'continueWritingChangedDocuments' is false ...
changedDocumentWorker.shutdown();
}
}
// PHASE 3:
// Perform the backup of the binary store ...
try {
int counter = 0;
for (BinaryKey binaryKey : binaryStore.getAllBinaryKeys()) {
try {
writeToContentArea(binaryKey, binaryStore.getInputStream(binaryKey));
++counter;
} catch (BinaryStoreException e) {
problems.addError(JcrI18n.problemsWritingBinaryToBackup, binaryKey, backupLocation(), e.getMessage());
}
}
LOGGER.debug("Wrote {0} binary values to {1}", counter, binaryDirectory.getAbsolutePath());
} catch (BinaryStoreException e) {
I18n msg = JcrI18n.problemsGettingBinaryKeysFromBinaryStore;
problems.addError(msg, repositoryName(), backupLocation(), e.getMessage());
}
// PHASE 4:
// Write all of the binary files that were added during the changes made while we worked ...
int counter = 0;
for (BinaryKey binaryKey : observer.getUsedBinaryKeys()) {
try {
writeToContentArea(binaryKey, binaryStore.getInputStream(binaryKey));
++counter;
} catch (BinaryStoreException e) {
problems.addError(JcrI18n.problemsWritingBinaryToBackup, binaryKey, backupLocation(), e.getMessage());
}
}
LOGGER.debug("Wrote {0} recent binary values to {1}", counter, binaryDirectory.getAbsolutePath());
// PHASE 5:
// And now write all binary keys for the binaries that were recorded as unused by the observer ...
writeToChangedArea(observer.getUnusedBinaryKeys());
// Wait for the changes to be written
changesLatch.await(30, TimeUnit.SECONDS);
LOGGER.debug("Completed backup of '{0}' repository into {1} (contains {2} nodes and {3} binary values)",
repositoryName(), backupLocation(),
contentWriter.getDocumentCount() + changesWriter.getDocumentCount(), numBinaryValues);
} catch (InterruptedException e) {
Thread.interrupted();
I18n msg = JcrI18n.interruptedWhilePerformingBackup;
this.problems.addError(msg, repositoryName(), backupLocation(), e.getMessage());
} catch (CancellationException e) {
this.problems.addError(JcrI18n.backupOperationWasCancelled, repositoryName(), backupLocation(), e.getMessage());
} finally {
// PHASE 5: