Search in sources :

Example 1 with RestoreHandler

use of org.exist.backup.restore.RestoreHandler in project exist by eXist-db.

the class Restore method restore.

public void restore(final DBBroker broker, @Nullable final Txn transaction, final String newAdminPass, final Path f, final RestoreListener listener, final boolean overwriteApps) throws EXistException, IOException, SAXException, PermissionDeniedException {
    // set the admin password
    if (newAdminPass != null) {
        setAdminCredentials(broker, newAdminPass);
    }
    // get the backup descriptors, can be more than one if it was an incremental backup
    final Deque<BackupDescriptor> descriptors = getBackupDescriptors(f);
    final Set<String> appsToSkip = overwriteApps ? Collections.emptySet() : AppRestoreUtils.checkApps(broker, descriptors);
    // count all files
    long totalNrOfFiles = 0;
    for (BackupDescriptor backupDescriptor : descriptors) {
        totalNrOfFiles += backupDescriptor.getNumberOfFiles();
    }
    // continue restore
    final XMLReaderPool parserPool = broker.getBrokerPool().getParserPool();
    XMLReader reader = null;
    try {
        reader = parserPool.borrowXMLReader();
        listener.started(totalNrOfFiles);
        while (!descriptors.isEmpty()) {
            final BackupDescriptor descriptor = descriptors.pop();
            if (appsToSkip.contains(descriptor.getSymbolicPath())) {
                listener.skipResources("Skipping app path " + descriptor.getSymbolicPath() + ". Newer version " + "is already installed.", descriptor.getNumberOfFiles());
            } else {
                final EXistInputSource is = descriptor.getInputSource();
                is.setEncoding(UTF_8.displayName());
                final RestoreHandler handler = new RestoreHandler(broker, transaction, descriptor, listener, appsToSkip);
                reader.setContentHandler(handler);
                reader.parse(is);
            }
        }
    } finally {
        listener.finished();
        if (reader != null) {
            parserPool.returnXMLReader(reader);
        }
    }
}
Also used : EXistInputSource(org.exist.util.EXistInputSource) RestoreHandler(org.exist.backup.restore.RestoreHandler) XMLReaderPool(org.exist.util.XMLReaderPool) XMLReader(org.xml.sax.XMLReader)

Aggregations

RestoreHandler (org.exist.backup.restore.RestoreHandler)1 EXistInputSource (org.exist.util.EXistInputSource)1 XMLReaderPool (org.exist.util.XMLReaderPool)1 XMLReader (org.xml.sax.XMLReader)1