For a one-time restore of a sharded cluster, use a Kubernetes Job. The process involves two distinct phases to ensure schema consistency across the cluster and data consistency on specific replicas.
Restore Workflow:
- Schema Restore: Run
restore_remote --schema --rm <BACKUP_NAME> on all replicas in the cluster. This ensures the table structures are identical everywhere. - Data Restore: Run
restore_remote --data <BACKUP_NAME> on only one replica per shard. This populates the data without creating duplicate data across replicas. - Cleanup: After a successful restore, run
delete local <BACKUP_NAME> to remove temporary files.
Key Environment Variables for the Restore Job:
CLICKHOUSE_SCHEMA_RESTORE_SERVICES: A comma-separated list of all service hostnames for schema restoration.CLICKHOUSE_DATA_RESTORE_SERVICES: A comma-separated list of hostnames (one per shard) for data restoration.BACKUP_USER / BACKUP_PASSWORD: Credentials for the ClickHouse cluster.
apiVersion: batch/v1
kind: Job
metadata:
name: clickhouse-backup-restore
spec:
template:
spec:
containers:
- name: clickhouse-backup-restore
image: clickhouse/clickhouse-client:latest
env:
- name: CLICKHOUSE_SCHEMA_RESTORE_SERVICES
value: "chi-test-backups-default-0-0,chi-test-backups-default-0-1,chi-test-backups-default-1-0,chi-test-backups-default-1-1"
- name: CLICKHOUSE_DATA_RESTORE_SERVICES
value: "chi-test-backups-default-0-0,chi-test-backups-default-1-0"
- name: CLICKHOUSE_PORT
value: "9000"
- name: BACKUP_USER
value: "backup"
- name: BACKUP_PASSWORD
value: "backup_password"
command:
- bash
- -ec
- |
# ... (bash script to execute restore_remote commands via system.backup_actions)