> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Using ON CLUSTER with BACKUP and RESTORE

> What BACKUP and RESTORE do with ON CLUSTER on a self-managed cluster, why every host needs the same backup destination, and how replicated and non-replicated tables are restored.

On a self-managed cluster, `BACKUP ... ON CLUSTER` makes every host of the cluster write its tables into one backup, and `RESTORE ... ON CLUSTER` creates the tables again on every host. Two rules apply: the destination must be storage that all hosts share, and it cannot be an archive file.

```sql theme={null}
BACKUP TABLE db.events ON CLUSTER 'my_cluster'
TO Disk('backups', 'events_2026_12_01');

RESTORE TABLE db.events AS db.events_restored ON CLUSTER 'my_cluster'
FROM Disk('backups', 'events_2026_12_01');
```

> [!NOTE]
>
> This article is about self-managed ClickHouse. In ClickHouse Cloud, backups are taken by the service. See [Backups](https://clickhouse.com/docs/products/cloud/features/backups/overview.md).

## What ON CLUSTER does

The host that receives the statement sends it to the other hosts of the cluster as a [distributed DDL query](https://clickhouse.com/docs/reference/statements/distributed-ddl.md). The hosts coordinate their work through ClickHouse Keeper, under the path set by `zookeeper_path` in the [`backups`](https://clickhouse.com/docs/reference/settings/server-settings/settings/backups#backups) server settings, and all of them write into the same destination:

* For replicated tables (the `ReplicatedMergeTree` family), the replicas agree on which of them stores each data part, and a file that several replicas have is stored once. The backup also contains the parts that had not reached every replica yet.
* For non-replicated tables (`MergeTree`), every host stores its own data separately, under its shard number and replica number in the cluster (`shard_num` and `replica_num` in [`system.clusters`](https://clickhouse.com/docs/reference/system-tables/clusters)).
* A table that you name in `BACKUP TABLE` must exist on every host of the cluster. Otherwise the statement fails with the error of the host that does not have it.

Without `ON CLUSTER`, `BACKUP` stores only what the host that runs the statement has. For a replicated table in a cluster with one shard, that is a complete copy as long as the replica is in sync. In a cluster with several shards, or for non-replicated tables, it is the data of that host only.

## The destination must be shared by all hosts

`Disk('backups', ...)` and `File(...)` are resolved by each host on its own. If they point to a local directory, every host looks at a different place. The host that received the statement creates a lock file in the destination, the other hosts do not find it, and the backup fails:

```text theme={null}
Lock file .lock suddenly disappeared while writing backup Disk('backups', 'events_2026_12_01'). (FAILED_TO_SYNC_BACKUP_OR_RESTORE)
```

Use a destination that is the same storage for every host:

* object storage, with [`S3(...)`](https://clickhouse.com/docs/concepts/features/backup-restore/s3-endpoint), [`AzureBlobStorage(...)`](https://clickhouse.com/docs/concepts/features/backup-restore/azure-blob-storage) or a [disk on object storage](https://clickhouse.com/docs/concepts/features/backup-restore/local-disk.md#backuprestore-using-an-s3-disk);
* a shared file system that is mounted at the same path on every host, with the same disk and `backups` configuration on every host.

## Archives are not supported

A destination with an archive extension, such as `.zip` or `.tar`, is rejected:

```text theme={null}
Using archives with backups on clusters is disabled. (SUPPORT_IS_DISABLED)
```

Use a name without an extension. The backup is then stored as a directory of files. The check is made on every host that takes part in a `BACKUP ... ON CLUSTER` or a `RESTORE ... ON CLUSTER`. A single host can write and read an archive without `ON CLUSTER`.

## Restoring with ON CLUSTER

`RESTORE ... ON CLUSTER` creates the tables on every host of the cluster and then restores the data:

* **Replicated tables.** One replica attaches the parts from the backup, and the other replicas receive them through replication. Wait for replication before you compare the hosts, for example with `SYSTEM SYNC REPLICA ON CLUSTER 'my_cluster' db.events_restored`.
* **Non-replicated tables.** Every host restores the data that was stored for its own shard number and replica number. A host whose table was empty when the backup was taken has an empty table after the restore. `ON CLUSTER` does not copy the rows of one host to the others.

## Restoring without ON CLUSTER

Without `ON CLUSTER`, `RESTORE` creates and fills the table only on the host that runs the statement:

* **A replicated table whose Keeper path contains `{uuid}`**, as the default path `/clickhouse/tables/{uuid}/{shard}` does, gets a new UUID and therefore a new path. The result is a separate table with one replica on that host.

* **A replicated table with a fixed Keeper path** is restored with the path of the original table. Restoring it under another name on a host that still has the original fails with `REPLICA_ALREADY_EXISTS`. If you dropped the table on this host only, the restored table joins the remaining replicas and receives their data through replication. If they have any data, `RESTORE` then fails with `Cannot restore the table ... because it already contains some data` (`CANNOT_RESTORE_TABLE`). The table exists after this error, but it holds the current data of the other replicas, not the data of the backup: rows that were deleted or changed after the backup was taken are not brought back. If a new replica with the current data is what you want, restore only the definition, which gives the same table without the error:

  ```sql theme={null}
  RESTORE TABLE db.events FROM Disk('backups', 'events_2026_12_01')
  SETTINGS structure_only = true;
  ```

  To get the rows of the backup, create an empty table that differs from the original only in its Keeper path (or in its engine: `MergeTree` instead of `ReplicatedMergeTree`), and restore into it:

  ```sql theme={null}
  RESTORE TABLE db.events AS db.events_from_backup FROM Disk('backups', 'events_2026_12_01')
  SETTINGS allow_different_table_def = true;
  ```

  Do not use `allow_non_empty_tables = true` on the re-created replica for this. It adds the parts of the backup to the data received from the other replicas, so rows that are in both are stored twice.

* **A non-replicated table from an `ON CLUSTER` backup** is filled with the data that was stored for the first replica of the first shard. To take the data of another host, name it with the `RESTORE` settings `shard_num_in_backup` and `replica_num_in_backup`:

  ```sql theme={null}
  RESTORE TABLE db.events AS db.events_copy FROM Disk('backups', 'events_2026_12_01')
  SETTINGS replica_num_in_backup = 2;
  ```

## Related pages

* [Backup and restore in ClickHouse](https://clickhouse.com/docs/concepts/features/backup-restore/overview.md) for the syntax and the settings of both statements.
* [`BACKUP` / `RESTORE` to disk](https://clickhouse.com/docs/concepts/features/backup-restore/local-disk) for the configuration of a backup disk.
* [`system.backups`](https://clickhouse.com/docs/reference/system-tables/backups) for the status and the error of an operation.
