Skip to content

bug: restore_remote with --restore-database-mapping fails for comma-separated --tables #1421

Description

@l4l4l4l4

Summary

restore_remote fails when --restore-database-mapping is used together with multiple comma-separated tables in --tables.

A single table restore works, but the same command with two tables fails after schema restore.

Command

clickhouse-backup restore_remote \
  --schema \
  --data \
  --tables=dwh.events,dwh.events_invalid \
  --restore-database-mapping=dwh:sandbox_tagafonov \
  incremental-2026-06-12

Observed Behavior

The restore starts and schema restore creates the target tables, then data restore fails:

RestoreData: restoreData: 'sandbox_tagafonov.events', 'sandbox_tagafonov.events_invalid' is not created. Restore schema first or create missing tables manually

Relevant log sequence:

/backup/actions call: restore_remote --schema --data --tables=dwh.events,dwh.events_invalid --restore-database-mapping=dwh:sandbox_tagafonov incremental-2026-06-12
CREATE DATABASE IF NOT EXISTS `sandbox_tagafonov` ...
CREATE TABLE sandbox_tagafonov.events ...
CREATE TABLE sandbox_tagafonov.events_invalid ...
done, backup=incremental-2026-06-12, operation=restore_schema
found 2 tables with data in backup
RestoreData: restoreData: 'sandbox_tagafonov.events', 'sandbox_tagafonov.events_invalid' is not created. Restore schema first or create missing tables manually

Debug logs show the existence check uses this generated pattern:

match(concat(database,'.',name),'^sandbox_tagafonov\..*sandbox_tagafonov\..*$')

That pattern cannot match real target tables such as:

sandbox_tagafonov.events
sandbox_tagafonov.events_invalid

Expected Behavior

The data restore phase should find the tables created by the schema restore phase and continue restoring data.

Expected matching pattern should be equivalent to:

sandbox_tagafonov.events,sandbox_tagafonov.events_invalid

or:

sandbox_tagafonov.*

Workarounds

Both of these work:

# Single table restore
clickhouse-backup restore_remote --schema --data --tables=dwh.events --restore-database-mapping=dwh:sandbox_tagafonov incremental-2026-06-12
# Wildcard table pattern
clickhouse-backup restore_remote --schema --data --tables=dwh.* --restore-database-mapping=dwh:sandbox_tagafonov incremental-2026-06-12

Regression Range

I checked tags using GitHub compare:

  • Latest known OK: v2.6.39
  • First known bad: v2.6.40
  • Also affected: v2.7.2

Likely introduced by:

  • d03d5155fb747773109844e9010a155d3fd28d39
  • d03d515

The suspicious function is changeTablePatternFromRestoreMapping().

Environment

  • clickhouse-backup: 2.7.2
  • Command path: API integration table / /backup/actions
  • ClickHouse version: 25.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions