Ejemplo n.º 1
0
 def test_compare_file_not_match(self, mock_get_hashes):
     """
     compute checksum for a file and it should not match
     """
     mock_get_hashes.return_value = self.hello_world_sha256sum
     chksum = CheckSum('onefile')
     self.assertFalse(chksum.compare('badchecksum'))
Ejemplo n.º 2
0
 def test_compare_dir_not_match(self, mock_get_hashes):
     """
     compute checksum for a directory and it should not match
     """
     mock_get_hashes.return_value = self.increment_hash_multi
     chksum = CheckSum('onedir')
     self.assertFalse(chksum.compare('badchecksum'))
Ejemplo n.º 3
0
    def execute(self):
        conf = self.conf
        LOG.info('Executing FS restore...')
        restore_timestamp = None

        restore_abs_path = conf.restore_abs_path
        if conf.restore_from_date:
            restore_timestamp = utils.date_to_timestamp(conf.restore_from_date)
        if conf.backup_media == 'fs':
            self.engine.restore(
                hostname_backup_name=self.conf.hostname_backup_name,
                restore_path=restore_abs_path,
                overwrite=conf.overwrite,
                recent_to_date=conf.restore_from_date)

            try:
                if conf.consistency_checksum:
                    backup_checksum = conf.consistency_checksum
                    restore_checksum = CheckSum(restore_abs_path,
                                                ignorelinks=True)
                    if restore_checksum.compare(backup_checksum):
                        LOG.info('Consistency check success.')
                    else:
                        raise ConsistencyCheckException(
                            "Backup Consistency Check failed: backup checksum "
                            "({0}) and restore checksum ({1}) did not match.".
                            format(backup_checksum, restore_checksum.checksum))
            except OSError as e:
                raise ConsistencyCheckException(
                    "Backup Consistency Check failed: could not checksum file"
                    " {0} ({1})".format(e.filename, e.strerror))
            return {}
        res = restore.RestoreOs(conf.client_manager, conf.container)
        if conf.backup_media == 'nova':
            LOG.info("Restoring nova backup. Instance ID: {0}, timestamp: {1}".
                     format(conf.nova_inst_id, restore_timestamp))
            nova_network = None
            if conf.nova_restore_network:
                nova_network = conf.nova_restore_network
            res.restore_nova(conf.nova_inst_id, restore_timestamp,
                             nova_network)
        elif conf.backup_media == 'cinder':
            LOG.info("Restoring cinder backup from glance. Volume ID: {0}, "
                     "timestamp: {1}".format(conf.cinder_vol_id,
                                             restore_timestamp))
            res.restore_cinder_by_glance(conf.cinder_vol_id, restore_timestamp)
        elif conf.backup_media == 'cindernative':
            LOG.info("Restoring cinder native backup. Volume ID {0}, Backup ID"
                     " {1}, timestamp: {2}".format(conf.cindernative_vol_id,
                                                   conf.cindernative_backup_id,
                                                   restore_timestamp))
            res.restore_cinder(conf.cindernative_vol_id,
                               conf.cindernative_backup_id, restore_timestamp)
        else:
            raise Exception("unknown backup type: %s" % conf.backup_media)
        return {}
Ejemplo n.º 4
0
    def execute_method(self):
        conf = self.conf
        logging.info('[*] Executing FS restore...')
        restore_timestamp = None

        restore_abs_path = conf.restore_abs_path
        if conf.restore_from_date:
            restore_timestamp = utils.date_to_timestamp(conf.restore_from_date)
        if conf.backup_media == 'fs':
            backup = self.storage.find_one(conf.hostname_backup_name,
                                           restore_timestamp)
            self.engine.restore(backup, restore_abs_path, conf.overwrite)

            try:
                if conf.consistency_checksum:
                    backup_checksum = conf.consistency_checksum
                    restore_checksum = CheckSum(restore_abs_path,
                                                ignorelinks=True)
                    if restore_checksum.compare(backup_checksum):
                        logging.info('[*] Consistency check success.')
                    else:
                        raise ConsistencyCheckException(
                            "Backup Consistency Check failed: backup checksum "
                            "({0}) and restore checksum ({1}) did not match.".
                            format(backup_checksum, restore_checksum.checksum))
            except OSError as e:
                raise ConsistencyCheckException(
                    "Backup Consistency Check failed: could not checksum file"
                    " {0} ({1})".format(e.filename, e.strerror))
            return {}

        res = restore.RestoreOs(conf.client_manager, conf.container)
        if conf.backup_media == 'nova':
            res.restore_nova(conf.nova_inst_id, restore_timestamp)
        elif conf.backup_media == 'cinder':
            res.restore_cinder_by_glance(conf.cinder_vol_id, restore_timestamp)
        elif conf.backup_media == 'cindernative':
            res.restore_cinder(conf.cindernative_vol_id, restore_timestamp)
        else:
            raise Exception("unknown backup type: %s" % conf.backup_media)
        return {}
Ejemplo n.º 5
0
    def execute_method(self):
        conf = self.conf
        logging.info('[*] Executing FS restore...')
        restore_timestamp = None

        restore_abs_path = conf.restore_abs_path
        if conf.restore_from_date:
            restore_timestamp = utils.date_to_timestamp(conf.restore_from_date)
        if conf.backup_media == 'fs':
            backup = self.storage.find_one(conf.hostname_backup_name,
                                           restore_timestamp)
            self.engine.restore(backup, restore_abs_path, conf.overwrite)

            try:
                if conf.consistency_checksum:
                    backup_checksum = conf.consistency_checksum
                    restore_checksum = CheckSum(restore_abs_path,
                                                ignorelinks=True)
                    if restore_checksum.compare(backup_checksum):
                        logging.info('[*] Consistency check success.')
                    else:
                        raise ConsistencyCheckException(
                            "Backup Consistency Check failed: backup checksum "
                            "({0}) and restore checksum ({1}) did not match.".
                            format(backup_checksum, restore_checksum.checksum))
            except OSError as e:
                raise ConsistencyCheckException(
                    "Backup Consistency Check failed: could not checksum file"
                    " {0} ({1})".format(e.filename, e.strerror))
            return {}

        res = restore.RestoreOs(conf.client_manager, conf.container)
        if conf.backup_media == 'nova':
            res.restore_nova(conf.nova_inst_id, restore_timestamp)
        elif conf.backup_media == 'cinder':
            res.restore_cinder_by_glance(conf.cinder_vol_id, restore_timestamp)
        elif conf.backup_media == 'cindernative':
            res.restore_cinder(conf.cindernative_vol_id, restore_timestamp)
        else:
            raise Exception("unknown backup type: %s" % conf.backup_media)
        return {}