'Restore volume backups from configured backup service.'

def restore_backup(self, context, backup, volume_id):

    LOG.info('Restore    backup    started,    backup:    %(backup_id)s    volume:    %(volume_id)s.', {'backup_id': backup.id, 'volume_id': volume_id})
    volume = objects.Volume.get_by_id(context, volume_id)
    self._notify_about_backup_usage(context, backup, 'restore.start')
    backup.host = self.host
    backup.save()
    expected_status = 'restoring-backup'
    actual_status = volume['status']
    if (actual_status != expected_status):
        err = (_('Restore    backup    aborted,    expected    volume    status    %(expected_status)s    but    got    %(actual_status)s.') % {'expected_status': expected_status, 'actual_status': actual_status})
        backup.status = fields.BackupStatus.AVAILABLE
        backup.save()
        raise exception.InvalidVolume(reason=err)
    expected_status = fields.BackupStatus.RESTORING
    actual_status = backup['status']
    if (actual_status != expected_status):
        err = (_('Restore    backup    aborted:    expected    backup    status    %(expected_status)s    but    got    %(actual_status)s.') % {'expected_status': expected_status, 'actual_status': actual_status})
        self._update_backup_error(backup, err)
        self.db.volume_update(context, volume_id, {'status': 'error'})
        raise exception.InvalidBackup(reason=err)
    if (volume['size'] > backup['size']):
        LOG.info('Volume:    %(vol_id)s,    size:    %(vol_size)d    is    larger    than    backup:    %(backup_id)s,    size:    %(backup_size)d,    continuing    with    restore.', {'vol_id': volume['id'], 'vol_size': volume['size'], 'backup_id': backup['id'], 'backup_size': backup['size']})
    backup_service = self._map_service_to_driver(backup['service'])
    configured_service = self.driver_name
    if (backup_service != configured_service):
        err = (_('Restore    backup    aborted,    the    backup    service    currently    configured    [%(configured_service)s]    is    not    the    backup    service    that    was    used    to    create    this    backup    [%(backup_service)s].') % {'configured_service': configured_service, 'backup_service': backup_service})
        backup.status = fields.BackupStatus.AVAILABLE
        backup.save()
        self.db.volume_update(context, volume_id, {'status': 'error'})
        raise exception.InvalidBackup(reason=err)
    try:
        self._run_restore(context, backup, volume)
    except Exception:
        with excutils.save_and_reraise_exception():
            self.db.volume_update(context, volume_id, {'status': 'error_restoring'})
            backup.status = fields.BackupStatus.AVAILABLE
            backup.save()
    self.db.volume_update(context, volume_id, {'status': 'available'})
    backup.status = fields.BackupStatus.AVAILABLE
    backup.save()
    LOG.info('Restore    backup    finished,    backup    %(backup_id)s    restored    to    volume    %(volume_id)s.', {'backup_id': backup.id, 'volume_id': volume_id})
    self._notify_about_backup_usage(context, backup, 'restore.end')
