Advanced clickhouse backup
ClickHouse Backup Guide
This guide covers the two backup options available for ClickHouse in Opik’s Kubernetes deployment:
- SQL-based Backup - Uses ClickHouse’s native
BACKUPcommand with S3 - ClickHouse Backup Tool - Uses the dedicated
clickhouse-backuptool
Overview
ClickHouse backup is essential for data protection and disaster recovery. Opik provides two different approaches to handle backups, each with its own advantages:
- SQL-based Backup: Simple, uses ClickHouse’s built-in backup functionality
- ClickHouse Backup Tool: More advanced, provides additional features like compression and incremental backups
Option 1: SQL-based Backup (Default)
This is the default backup method that uses ClickHouse’s native BACKUP command to create backups directly to S3-compatible storage.
Features
- Uses ClickHouse’s built-in
BACKUP ALL EXCEPT DATABASE systemcommand - Direct S3 upload with timestamped backup names
- Configurable schedule via CronJob
- Supports both AWS S3 and S3-compatible storage (like MinIO)
Configuration
Basic Setup
With AWS S3 Credentials
Create a Kubernetes secret with your S3 credentials:
Then configure the backup:
With IAM Role (AWS EKS)
For AWS EKS clusters, you can use IAM roles instead of access keys:
Required IAM Policy:
Trust Relationship Policy:
Custom Backup Command
You can customize the backup command if needed:
Backup Process
The SQL-based backup:
- Creates a timestamped backup name (format:
backupYYYYMMDDHHMM) - Executes
BACKUP ALL EXCEPT DATABASE system TO S3(...)command - Uploads all databases except the
systemdatabase to S3 - Uses ClickHouse’s native backup format
Restore Process
To restore from a SQL-based backup:
Option 2: ClickHouse Backup Tool
The ClickHouse Backup Tool provides more advanced backup features including compression, incremental backups, and better restore capabilities.
Features
- Advanced backup management with compression
- Incremental backup support
- REST API for backup operations
- Better restore capabilities
- Backup metadata and validation
Configuration
Enable Backup Server
Configure S3 Storage
Set up S3 configuration for the backup tool:
With Kubernetes Secrets
Use Kubernetes secrets for sensitive data:
(can be ignored when using IAM roles)
Using the Backup Tool
Create Backup
Upload Backup to S3
Download and Restore
Automated Backup with CronJob
You can create a custom CronJob to automate the backup tool:
Automated Restore with Kubernetes Job
The Opik helm chart ships a Kubernetes Job that runs a complete restore: it picks restore or
restore_remote depending on whether the backup is already on local disk, starts it through the
backup server API, and polls until it finishes.
The backup server must be enabled before the restore, and the backup must already exist and have been created by the backup server — not by the SQL-based backup in Option 1.
The restore replaces data. clickhouse-backup drops and recreates every table contained in the backup (ON CLUSTER when RESTORE_SCHEMA_ON_CLUSTER is set) before restoring it, so you do not need to drop databases or tables yourself. Tables that are not part of the backup are left untouched.
One exception: if restore_schema_on_cluster is set through a config file while the RESTORE_SCHEMA_ON_CLUSTER environment variable is empty, clickhouse-backup refuses to drop tables that still hold data and the restore aborts. Set it as an environment variable, as the values example below does.
The job does not retry (backoffLimit: 0) and is capped by activeDeadlineSeconds — 24 hours by default. Raise it for large restores, or Kubernetes will kill the job mid-restore.
Find the backup name
backupName is required, and must match a name the backup server knows:
Use the name field, not the S3 prefix. With S3_PATH: shard-{shard}, a backup stored at
s3://your-bucket/shard-0/2026-07-28/ has the name 2026-07-28.
The service, pod and port used throughout this section are the chart defaults, matching the
RESTORE_SERVICE the Job computes. If you set nameOverride, a different shard/replica layout, or
clickhouse.backupServer.service.name / .port, substitute your own — list them with
kubectl get pods,svc -n <namespace> -l clickhouse.altinity.com/chi. The port is
clickhouse.backupServer.service.port when set, and otherwise clickhouse.backupServer.port
(7171 by default).
Render the job manifest
The backup server has to be running in the release already. The command below renders only
the Job, so nothing under backupServer reaches the cluster through it — if the server is not
enabled yet, roll it out with helm upgrade first:
Then put the restore settings, which are only needed at render time, in their own values file:
Render only the restore job. Pass your existing values file first, so the job inherits the same service account, node selector and tolerations as your ClickHouse pods:
helm template does not write a namespace into the manifest, so either add namespace: to the
job’s metadata or pass -n when you apply it.
Create the job
The job is named <opik.name>-clickhouse-restore — opik-clickhouse-restore unless you set
nameOverride, and always readable as metadata.name in the manifest you just rendered. Use
that name in the commands here and in the next step. It is fixed per release, so delete the
previous job before restoring again:
Re-applying is safe: if this backup was already restored the Job exits without restoring it again, and if a restore is still running — for example after its pod was rescheduled — it follows that one instead of starting a second.
Checking progress during a long restore
The job’s own log only reports in progress. For actual progress, use these — in increasing
cost order.
Per-table progress, from the backup server’s log:
Each line is one finished table: progress=9/44 size=457.38GiB table=opik_prod.spans. Note that
9/44 is the table’s position in the list, not a count of finished tables — count the
distinct positions you have seen, or the numerator will look stuck while most tables are done.
Current status and start time:
Bytes landed on disk, against the backup’s own size:
Two df readings a few minutes apart give a rough throughput and ETA, but treat that as a coarse
capacity check rather than restore progress: df reports the whole volume, so merges, system tables
and any other writes land in the same delta, and the total can pass the backup’s data_size before
the restore is done. The per-table download_data lines above are the authoritative signal. Prefer
df over du -sb on the backup directory either way: du walks every file in a multi-terabyte tree
and adds significant I/O to the volume the restore is already saturating.
The /backup/actions history is kept in memory. It is empty if the backup-server container restarted since the restore began, so this is a live-progress tool only — after the fact there is no local record. If you scrape metrics, kubelet_volume_stats_used_bytes for the ClickHouse PVC is the durable equivalent and needs no exec.
Setting createJob: true in your release values works too — helm upgrade then creates the same job. If you do that, set it back to false afterwards, otherwise the next helm upgrade re-creates the job and restores again. The “already restored” check reads the backup server’s in-memory action history, so it does not survive a backup server restart.
Comparison
Best Practices
General Recommendations
- Test Restores: Regularly test backup restoration procedures
- Monitor Backup Jobs: Set up monitoring for backup job failures
- Retention Policy: Implement backup retention policies
- Cross-Region: Consider cross-region backup replication for disaster recovery
Security
- Access Control: Use IAM roles when possible instead of access keys
- Encryption: Enable S3 server-side encryption for backup storage
- Network Security: Use VPC endpoints for S3 access when available
Performance
- Schedule: Run backups during low-traffic periods
- Resource Limits: Set appropriate resource limits for backup jobs
- Storage Class: Use appropriate S3 storage classes for cost optimization
Troubleshooting
Common Issues
Backup Job Fails
S3 Access Issues
Backup Tool API Issues
Monitoring
Set up monitoring for backup operations:
Migration Between Backup Methods
From SQL-based to ClickHouse Backup Tool
-
Enable the backup server:
-
Create initial backup with the tool
-
Disable SQL-based backup:
From ClickHouse Backup Tool to SQL-based
-
Disable backup server:
-
Enable SQL-based backup:
Support
For additional help with ClickHouse backups: