'Restore the given volume backup from backup repository.'

def restore(self, backup, volume_id, volume_file):

    backup_id = backup['id']
    container = backup['container']
    object_prefix = backup['service_metadata']
    LOG.debug('starting    restore    of    backup    %(object_prefix)s    container:    %(container)s,    to    volume    %(volume_id)s,    backup:    %(backup_id)s.', {'object_prefix': object_prefix, 'container': container, 'volume_id': volume_id, 'backup_id': backup_id})
    metadata = self._read_metadata(backup)
    metadata_version = metadata['version']
    LOG.debug('Restoring    backup    version    %s', metadata_version)
    try:
        restore_func = getattr(self, self.DRIVER_VERSION_MAPPING.get(metadata_version))
    except TypeError:
        err = (_('No    support    to    restore    backup    version    %s') % metadata_version)
        raise exception.InvalidBackup(reason=err)
    backup_list = []
    backup_list.append(backup)
    current_backup = backup
    while current_backup.parent_id:
        prev_backup = objects.Backup.get_by_id(self.context, current_backup.parent_id)
        backup_list.append(prev_backup)
        current_backup = prev_backup
    index = (len(backup_list) - 1)
    while (index >= 0):
        backup1 = backup_list[index]
        index = (index - 1)
        metadata = self._read_metadata(backup1)
        restore_func(backup1, volume_id, metadata, volume_file)
        volume_meta = metadata.get('volume_meta', None)
        try:
            if volume_meta:
                self.put_metadata(volume_id, volume_meta)
            else:
                LOG.debug('No    volume    metadata    in    this    backup.')
        except exception.BackupMetadataUnsupportedVersion:
            msg = _('Metadata    restore    failed    due    to    incompatible    version.')
            LOG.error(msg)
            raise exception.BackupOperationError(msg)
    LOG.debug('restore    %(backup_id)s    to    %(volume_id)s    finished.', {'backup_id': backup_id, 'volume_id': volume_id})
