Class BackupManager


  • public class BackupManager
    extends Object
    This is the primary class for managing backups, it works on top of an arbitrary backup storage and allows to backup and restore backupable entities as well as listing and verifying backups. A backup manager does not cache the backup storage content. Multiple backup managers from any DS instance in the topology, working on top of the same backup storage may concurrently call any of the backup manager methods.
    • Constructor Detail

      • BackupManager

        public BackupManager​(BackupFileManager backupFileManager,
                             String serverId)
        Constructor.
        Parameters:
        backupFileManager - the backup file manager
        serverId - the server id
    • Method Detail

      • newBackupManager

        public static BackupManager newBackupManager​(BackupStorage backupStorage,
                                                     ServerContext serverContext)
                                              throws com.forgerock.opendj.cli.ClientException
        Creates a new backup manager backed by the provided backup storage.
        Parameters:
        backupStorage - The backup storage where to read and write backups.
        serverContext - The server context.
        Returns:
        A backup manager backed by the provided backup storage.
        Throws:
        com.forgerock.opendj.cli.ClientException - If there is an error when trying to obtain the server ID.
      • createBackup

        public Backup createBackup​(Backupable backupable,
                                   Cancellable cancellable)
                            throws BackupException,
                                   LdapException
        Backs up a backend to the underlying backup storage.
        Parameters:
        backupable - The backend to be backed up.
        cancellable - A way to interrupt the backup operation.
        Returns:
        The backup that was just created.
        Throws:
        BackupException - If there is a problem when storing files to the underlying backup storage.
        LdapException - If there is a problem when reading backend data.
      • restoreBackup

        public void restoreBackup​(Backup backup,
                                  Backupable backupable,
                                  Cancellable cancellable)
                           throws BackupException,
                                  InitializationException
        Restores a backend from the underlying backup storage. If the backend directory does not exist, it will be created in order to easily initialize a backend from a backup. Before restoring, this method verifies that the underlying backup storage contains all the backup files needed for a complete restore. After this verification, all the current backend files are removed. Backup file integrity is only verified each time a file is completely transferred, if one backup file corruption is detected or if there is an IO error, restore will stop and all the backend files will be removed, leaving the backend empty.
        Parameters:
        backup - The backup to be restored.
        backupable - The backend to be restored.
        cancellable - A way to interrupt the restore operation.
        Throws:
        BackupException - If backup files are missing, corrupted or their integrity cannot be verified.
        InitializationException - If there was a problem when trying to replace the current backend files with the backup files.
      • verifyBackups

        public void verifyBackups​(Collection<Backup> backups,
                                  Cancellable cancellable)
        Verifies the integrity of the provided backups and mark them as Backup.verified() or Backup.hasErrors(). The errors can be retrieved with Backup.getErrors(). The integrity of each backend file will be verified only once even if files are shared across the provided backups.
        Parameters:
        backups - The backups to be verified.
        cancellable - A way to interrupt the verification.
      • listBackups

        public Collection<Backup> listBackups​(BackupManager.BackupFilter backupFilter,
                                              Collection<LocalizableMessage> errors)
                                       throws BackupException
        Lists all the backups without verifying their integrity. The returned collection has no specific order. This method does best effort to list all the backups, if there is an error when trying to read a backup, the error message is added to the provided error collection and the method does not throw an exception.
        Parameters:
        backupFilter - Filters the backups that wil be returned.
        errors - A collection where each error message encountered when trying to read a backup will be added.
        Returns:
        A collection containing all the backups.
        Throws:
        BackupException - If it is not possible to read the backup storage content.
      • purgeBackups

        public void purgeBackups​(Set<BackupId> backupsToDelete,
                                 Cancellable cancellable)
                          throws BackupException
        Purge a set of backups. The purge operation aims to delete all the files related to the given backup. If a purge operation has been interrupted, calling this method again will purge any remaining dangling data files.
        Parameters:
        backupsToDelete - The backupIds of the backups to purge.
        cancellable - A way to interrupt the restore operation.
        Throws:
        BackupException - whenever an error occurred while purging the backup.