Пример #1
0
 def _create_backupset(self):
     self._raise_if_backupset_exists()
     disk_details = DiskDetect.get_disk_details(self.disk)
     self.backupset = Backupset(self.backup_id)
     self.backupset.disk_layout = self._disk_layout.get_layout()
     self.backupset.disk_size = disk_details['size']
     self.backupset.compressed = self.config['compress']
     self.backupset.add_partitions(disk_details['partitions'])
     self.backupset.save()
Пример #2
0
 def __init__(self, backup_id):
     super(MountController, self).__init__(backup_id)
     self.nodes = []
     self.backupset = Backupset.load(backup_id)
     self.squash_wrapper = None
     self.mount_path = ConfigHelper.config['node'][
         'mount_path'] + self.backupset.id + '/'
Пример #3
0
 def _load_backupset(self):
     self.backupset = Backupset.load(self.backup_id)
     if self.backupset.node == ConfigHelper.config['node']['name']:
         return self.backupset
     else:
         raise Exception(
             'This backup resides on another node, terminating.')
Пример #4
0
 def _create_backupset(self):
     self._raise_if_backupset_exists()
     disk_details = DiskDetect.get_disk_details(self.disk)
     self.backupset = Backupset(self.backup_id)
     self.backupset.disk_layout = self._disk_layout.get_layout()
     self.backupset.disk_size = disk_details['size']
     self.backupset.compressed = self.config['compress']
     self.backupset.add_partitions(disk_details['partitions'])
     self.backupset.save()
Пример #5
0
 def _remove_previous_backup(self):
     try:
         backupset = Backupset.load(self.backup_id)
         delete_backup(backupset)
     except BackupsetException as e:
         pass
     except DiskImageException as e:
         self._set_error(str(e))
         raise e
Пример #6
0
 def _remove_previous_backup(self):
     try:
         backupset = Backupset.load(self.backup_id)
         delete_backup(backupset)
     except BackupsetException as e:
         pass
     except DiskImageException as e:
         self._set_error(str(e))
         raise e
Пример #7
0
 def _raise_if_backupset_exists(self):
     try:
         backupset = Backupset.load(self.backup_id)
         if not backupset.deleted:
             error_msg = "Backup with the id '" + self.backup_id + \
                         "' already exists and is not marked for deletion."
             self._set_error(error_msg)
             raise DiskImageException(error_msg)
     except BackupsetException:
         pass
Пример #8
0
 def _raise_if_backupset_exists(self):
     try:
         backupset = Backupset.load(self.backup_id)
         if not backupset.deleted:
             error_msg = "Backup with the id '" + self.backup_id + \
                         "' already exists and is not marked for deletion."
             self._set_error(error_msg)
             raise DiskImageException(error_msg)
     except BackupsetException:
         pass
Пример #9
0
 def __init__(self, backup_id):
     super(MountController, self).__init__(backup_id)
     self.nodes = []
     self.backupset = Backupset.load(backup_id)
     self.squash_wrapper = None
     self.mount_path = ConfigHelper.config['node']['mount_path'] + self.backupset.id + '/'
Пример #10
0
 def _load_backupset(self):
     self.backupset = Backupset.load(self.backup_id)
     if self.backupset.node == ConfigHelper.config['node']['name']:
         return self.backupset
     else:
         raise Exception('This backup resides on another node, terminating.')
Пример #11
0
class BackupController(ProcessController):
    """ The controller used to manage a complete Backup procedure """
    def __init__(self, disk, backup_id, config):
        super(BackupController, self).__init__(disk, backup_id, config)
        try:
            self._disk_layout = DiskLayout.with_config(self.disk, self.backup_dir, config)
        except Exception as e:
            self._set_error(str(e))
            raise DiskImageException(str(e))
        self._handle_overwrite(self.config['overwrite'])
        self._create_backupset()
        self._imager = PartitionImage.with_config(self.disk, self.backup_dir, self.backupset, config)

    def run(self):
        """
        Starts the execution of the backup procedure on a separate thread.
        :return: None
        """
        self._thread = Thread(target=self._backup)
        self._thread.start()

    def _handle_overwrite(self, overwrite):
        if overwrite:
            self._remove_previous_backup()
        if not overwrite and path.exists(self.backup_dir):
            error_msg = "Some files for the backup with id '" + self.backup_id + "' already exist "\
                            "and the overwrite option was not selected."
            self._set_error(error_msg)
            raise DiskImageException(error_msg)

    def _remove_previous_backup(self):
        try:
            backupset = Backupset.load(self.backup_id)
            delete_backup(backupset)
        except BackupsetException as e:
            pass
        except DiskImageException as e:
            self._set_error(str(e))
            raise e

    def _init_status(self):
        self._status['operation'] = 'Backup'
        self._status['status'] = constants.STATUS_RUNNING
        self._status['start_time'] = datetime.today().strftime(constants.DATE_FORMAT)
        self._status['path'] = self.backup_dir
        self._status['layout'] = self.backupset.disk_layout

    def _backup(self):
        if not self.has_error_status():
            try:
                self._init_status()
                self._create_backup_directory()
                self._disk_layout.backup_layout()
                self._imager.backup()
                self._status['status'] = constants.STATUS_FINISHED
            except Exception as e:
                self._set_error(e)
            finally:
                self._status['end_time'] = datetime.today().strftime(constants.DATE_FORMAT)
                self._complete_backupset()

    def _create_backup_directory(self):
        if not path.exists(self.backup_dir):
            try:
                makedirs(self.backup_dir)
            except IOError as e:
                logging.error('Cannot create path for backup: ' + self.backup_dir +
                              '. Cause:' + str(e))
                raise e

    def _create_backupset(self):
        self._raise_if_backupset_exists()
        disk_details = DiskDetect.get_disk_details(self.disk)
        self.backupset = Backupset(self.backup_id)
        self.backupset.disk_layout = self._disk_layout.get_layout()
        self.backupset.disk_size = disk_details['size']
        self.backupset.compressed = self.config['compress']
        self.backupset.add_partitions(disk_details['partitions'])
        self.backupset.save()

    def _raise_if_backupset_exists(self):
        try:
            backupset = Backupset.load(self.backup_id)
            if not backupset.deleted:
                error_msg = "Backup with the id '" + self.backup_id + \
                            "' already exists and is not marked for deletion."
                self._set_error(error_msg)
                raise DiskImageException(error_msg)
        except BackupsetException:
            pass

    def _complete_backupset(self):
        self.backupset.status = self._status['status']
        self.backupset.backup_size = sum(path.getsize(self.backup_dir + file)
                                         for file in listdir(self.backup_dir))
        self.backupset.save()
Пример #12
0
 def _purge_backup(self, backup):
     _remove_backup_files(Backupset.load(backup['id']))
Пример #13
0
 def _purge_backup(self, backup):
     _remove_backup_files(Backupset.load(backup['id']))
Пример #14
0
class BackupController(ProcessController):
    """ The controller used to manage a complete Backup procedure """
    def __init__(self, disk, backup_id, config):
        super(BackupController, self).__init__(disk, backup_id, config)
        try:
            self._disk_layout = DiskLayout.with_config(self.disk,
                                                       self.backup_dir, config)
        except Exception as e:
            self._set_error(str(e))
            raise DiskImageException(str(e))
        self._handle_overwrite(self.config['overwrite'])
        self._create_backupset()
        self._imager = PartitionImage.with_config(self.disk, self.backup_dir,
                                                  self.backupset, config)

    def run(self):
        """
        Starts the execution of the backup procedure on a separate thread.
        :return: None
        """
        self._thread = Thread(target=self._backup)
        self._thread.start()

    def _handle_overwrite(self, overwrite):
        if overwrite:
            self._remove_previous_backup()
        if not overwrite and path.exists(self.backup_dir):
            error_msg = "Some files for the backup with id '" + self.backup_id + "' already exist "\
                            "and the overwrite option was not selected."
            self._set_error(error_msg)
            raise DiskImageException(error_msg)

    def _remove_previous_backup(self):
        try:
            backupset = Backupset.load(self.backup_id)
            delete_backup(backupset)
        except BackupsetException as e:
            pass
        except DiskImageException as e:
            self._set_error(str(e))
            raise e

    def _init_status(self):
        self._status['operation'] = 'Backup'
        self._status['status'] = constants.STATUS_RUNNING
        self._status['start_time'] = datetime.today().strftime(
            constants.DATE_FORMAT)
        self._status['path'] = self.backup_dir
        self._status['layout'] = self.backupset.disk_layout

    def _backup(self):
        if not self.has_error_status():
            try:
                self._init_status()
                self._create_backup_directory()
                self._disk_layout.backup_layout()
                self._imager.backup()
                self._status['status'] = constants.STATUS_FINISHED
            except Exception as e:
                self._set_error(e)
            finally:
                self._status['end_time'] = datetime.today().strftime(
                    constants.DATE_FORMAT)
                self._complete_backupset()

    def _create_backup_directory(self):
        if not path.exists(self.backup_dir):
            try:
                makedirs(self.backup_dir)
            except IOError as e:
                logging.error('Cannot create path for backup: ' +
                              self.backup_dir + '. Cause:' + str(e))
                raise e

    def _create_backupset(self):
        self._raise_if_backupset_exists()
        disk_details = DiskDetect.get_disk_details(self.disk)
        self.backupset = Backupset(self.backup_id)
        self.backupset.disk_layout = self._disk_layout.get_layout()
        self.backupset.disk_size = disk_details['size']
        self.backupset.compressed = self.config['compress']
        self.backupset.add_partitions(disk_details['partitions'])
        self.backupset.save()

    def _raise_if_backupset_exists(self):
        try:
            backupset = Backupset.load(self.backup_id)
            if not backupset.deleted:
                error_msg = "Backup with the id '" + self.backup_id + \
                            "' already exists and is not marked for deletion."
                self._set_error(error_msg)
                raise DiskImageException(error_msg)
        except BackupsetException:
            pass

    def _complete_backupset(self):
        self.backupset.status = self._status['status']
        self.backupset.backup_size = sum(
            path.getsize(self.backup_dir + file)
            for file in listdir(self.backup_dir))
        self.backupset.save()