Search in sources :

Example 1 with Backup

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

the class BackupTask method execute.

@Override
public void execute() throws BuildException {
    if (uri == null) {
        throw (new BuildException("you have to specify an XMLDB collection URI"));
    }
    if (dir == null) {
        throw (new BuildException("missing required parameter: dir"));
    }
    registerDatabase();
    log("Creating backup of collection: " + uri);
    log("Backup directory: " + dir);
    try {
        final Backup backup = new Backup(user, password, Paths.get(dir), XmldbURI.create(uri), null, deduplicateBlobs);
        backup.backup(false, null);
    } catch (final Exception e) {
        e.printStackTrace();
        final String msg = "Exception during backup: " + e.getMessage();
        if (failonerror) {
            throw (new BuildException(msg, e));
        } else {
            log(msg, e, Project.MSG_ERR);
        }
    }
}
Also used : Backup(org.exist.backup.Backup) BuildException(org.apache.tools.ant.BuildException) BuildException(org.apache.tools.ant.BuildException)

Example 2 with Backup

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

the class BackupSystemTask method execute.

@Override
public void execute(final DBBroker broker, final Txn transaction) throws EXistException {
    // see if old zip files need to be purged
    if (zipFilesMax > 0) {
        try {
            purgeZipFiles();
        } catch (final IOException ioe) {
            throw new EXistException("Unable to purge zip files", ioe);
        }
    }
    final String dateTime = creationDateFormat.format(Calendar.getInstance().getTime());
    final Path dest = directory.resolve(prefix + dateTime + suffix);
    final Backup backup = new Backup(user, password, dest, collection, null, deduplicateBlobs);
    try {
        backup.backup(false, null);
    } catch (final XMLDBException | SAXException | IOException e) {
        LOG.error(e.getMessage(), e);
        throw new EXistException(e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) Backup(org.exist.backup.Backup) XMLDBException(org.xmldb.api.base.XMLDBException) IOException(java.io.IOException) EXistException(org.exist.EXistException) SAXException(org.xml.sax.SAXException)

Example 3 with Backup

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

the class RpcConnection method backup.

@Override
public boolean backup(final String userbackup, final String password, final String destcollection, final String collection) throws EXistException, PermissionDeniedException {
    try {
        final Backup backup = new Backup(userbackup, password, Paths.get(destcollection + "-backup"), XmldbURI.xmldbUriFor(XmldbURI.EMBEDDED_SERVER_URI.toString() + collection));
        backup.backup(false, null);
    } catch (final URISyntaxException | IOException | SAXException | XMLDBException e) {
        throw new EXistException(e);
    }
    return true;
}
Also used : Backup(org.exist.backup.Backup) URISyntaxException(java.net.URISyntaxException) EXistException(org.exist.EXistException) SAXException(org.xml.sax.SAXException)

Example 4 with Backup

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

the class ClientFrame method backupAction.

private void backupAction(final ActionEvent ev) {
    // get the collection to highlight in the backup dialog
    final String defaultSelectedCollection;
    final ResourceDescriptor[] selResources = getSelectedResources();
    if (selResources != null) {
        if (selResources.length == 1 && selResources[0].isCollection()) {
            // use the selected collection
            defaultSelectedCollection = path.toString() + "/" + selResources[0].getName().toString();
        } else {
            // use the current collection
            defaultSelectedCollection = path.toString();
        }
    } else {
        defaultSelectedCollection = path.toString();
    }
    final CreateBackupDialog dialog = new CreateBackupDialog(properties.getProperty(InteractiveClient.URI, "xmldb:exist://"), properties.getProperty(InteractiveClient.USER, SecurityManager.DBA_USER), properties.getProperty(InteractiveClient.PASSWORD, null), Paths.get(preferences.get("directory.backup", System.getProperty("user.home"))), defaultSelectedCollection);
    if (JOptionPane.showOptionDialog(this, dialog, Messages.getString("ClientFrame.157"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null) == JOptionPane.YES_OPTION) {
        final String collection = dialog.getCollection();
        final String backuptarget = dialog.getBackupTarget();
        final boolean deduplicateBlobs = dialog.getDeduplicateBlobs();
        final Path target = Paths.get(backuptarget).normalize();
        if (Files.exists(target)) {
            final int response = JOptionPane.showConfirmDialog(this, String.format("%s %s %s", Messages.getString("CreateBackupDialog.6a"), backuptarget, Messages.getString("CreateBackupDialog.6b")), Messages.getString("CreateBackupDialog.6c"), JOptionPane.YES_NO_OPTION);
            if (response == JOptionPane.YES_OPTION) {
                // User wants file/directory to be removed
                deleteDirectory(target);
            } else {
                JOptionPane.showMessageDialog(null, "Backup aborted, backup has not been deleted.");
                return;
            }
        }
        try {
            final Backup backup = new Backup(properties.getProperty(InteractiveClient.USER, SecurityManager.DBA_USER), properties.getProperty(InteractiveClient.PASSWORD, null), Paths.get(backuptarget), XmldbURI.xmldbUriFor(properties.getProperty(InteractiveClient.URI, "xmldb:exist://") + collection), null, deduplicateBlobs);
            backup.backup(true, this);
        } catch (final XMLDBException | IOException | SAXException | URISyntaxException e) {
            showErrorMessage(e.getClass().getSimpleName() + ": " + e.getMessage(), e);
        }
    }
}
Also used : Path(java.nio.file.Path) Backup(org.exist.backup.Backup) XMLDBException(org.xmldb.api.base.XMLDBException) URISyntaxException(java.net.URISyntaxException) CreateBackupDialog(org.exist.backup.CreateBackupDialog) SAXException(org.xml.sax.SAXException)

Example 5 with Backup

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

the class BackupRestoreSecurityPrincipalsTest method backupDatabase.

/**
 * Backup the database.
 *
 * @return The path to the database backup.
 */
private Path backupDatabase() throws IOException, XMLDBException, SAXException {
    final Path backupFile = Files.createTempFile(BACKUP_FILE_PREFIX, BACKUP_FILE_SUFFIX);
    backupFile.toFile().deleteOnExit();
    final Backup backup = new Backup(TestUtils.ADMIN_DB_USER, TestUtils.ADMIN_DB_PWD, backupFile);
    backup.backup(false, null);
    return backupFile;
}
Also used : Path(java.nio.file.Path) Backup(org.exist.backup.Backup)

Aggregations

Backup (org.exist.backup.Backup)5 Path (java.nio.file.Path)3 SAXException (org.xml.sax.SAXException)3 URISyntaxException (java.net.URISyntaxException)2 EXistException (org.exist.EXistException)2 XMLDBException (org.xmldb.api.base.XMLDBException)2 IOException (java.io.IOException)1 BuildException (org.apache.tools.ant.BuildException)1 CreateBackupDialog (org.exist.backup.CreateBackupDialog)1