Skip to content

Commit d5de0d2

Browse files
authored
STAC-23600: Restore Clickhouse (#7)
1 parent 8e3e7b5 commit d5de0d2

33 files changed

+1832
-311
lines changed

ARCHITECTURE.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ stackstate-backup-cli/
2020
│ ├── root.go # Root command and global flags
2121
│ ├── version/ # Version information command
2222
│ ├── elasticsearch/ # Elasticsearch backup/restore commands
23+
│ ├── clickhouse/ # ClickHouse backup/restore commands
2324
│ ├── stackgraph/ # Stackgraph backup/restore commands
24-
│ └── victoriametrics/ # VictoriaMetrics backup/restore commands
25+
│ ├── victoriametrics/ # VictoriaMetrics backup/restore commands
26+
│ └── settings/ # Settings backup/restore commands
2527
2628
├── internal/ # Internal packages (Layers 0-3)
2729
│ ├── foundation/ # Layer 0: Core utilities
@@ -63,9 +65,11 @@ stackstate-backup-cli/
6365
- Formats output for end users
6466

6567
**Key Packages**:
66-
- `cmd/elasticsearch/`: Elasticsearch snapshot/restore commands (configure, list-snapshots, list-indices, restore-snapshot)
68+
- `cmd/elasticsearch/`: Elasticsearch snapshot/restore commands (configure, list, list-indices, restore, check-and-finalize)
69+
- `cmd/clickhouse/`: ClickHouse backup/restore commands (list, restore, check-and-finalize)
6770
- `cmd/stackgraph/`: Stackgraph backup/restore commands (list, restore, check-and-finalize)
6871
- `cmd/victoriametrics/`: VictoriaMetrics backup/restore commands (list, restore, check-and-finalize)
72+
- `cmd/settings/`: Settings backup/restore commands (list, restore, check-and-finalize)
6973
- `cmd/version/`: Version information
7074

7175
**Dependency Rules**:
@@ -140,6 +144,7 @@ appCtx.Formatter
140144
**Key Packages**:
141145
- `k8s/`: Kubernetes API operations (Jobs, Pods, Deployments, ConfigMaps, Secrets, Logs)
142146
- `elasticsearch/`: Elasticsearch HTTP API (snapshots, indices, datastreams)
147+
- `clickhouse/`: ClickHouse Backup API and SQL operations (backups, restore operations, status tracking)
143148
- `s3/`: S3/Minio operations (client creation, object filtering)
144149

145150
**Dependency Rules**:
@@ -407,7 +412,7 @@ endpoint := "http://localhost:9200"
407412
### ❌ Don't: Create Clients Directly in Commands
408413

409414
```go
410-
// BAD: cmd/elasticsearch/list-snapshots.go
415+
// BAD: cmd/elasticsearch/list.go
411416
func runListSnapshots(globalFlags *config.CLIGlobalFlags) error {
412417
k8sClient, _ := k8s.NewClient(globalFlags.Kubeconfig, globalFlags.Debug)
413418
esClient, _ := elasticsearch.NewClient("http://localhost:9200")

README.md

Lines changed: 123 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ This CLI tool replaces the legacy Bash-based backup/restore scripts with a singl
88

99
**Current Support:**
1010
- Elasticsearch snapshots and restores
11+
- ClickHouse backups and restores
1112
- Stackgraph backups and restores
1213
- VictoriaMetrics backups and restores
13-
14-
**Planned:** ClickHouse, Configuration backups
14+
- Settings backups and restores
1515

1616
## Installation
1717

@@ -69,26 +69,43 @@ List Elasticsearch indices.
6969
sts-backup elasticsearch list-indices --namespace <namespace>
7070
```
7171

72-
#### list-snapshots
72+
#### list
7373

7474
List available Elasticsearch snapshots.
7575

7676
```bash
77-
sts-backup elasticsearch list-snapshots --namespace <namespace>
77+
sts-backup elasticsearch list --namespace <namespace>
7878
```
7979

80-
#### restore-snapshot
80+
#### restore
8181

8282
Restore Elasticsearch snapshot. Automatically scales down affected deployments before restore and scales them back up afterward.
8383

8484
```bash
85-
sts-backup elasticsearch restore-snapshot --namespace <namespace> --snapshot-name <name> [flags]
85+
sts-backup elasticsearch restore --namespace <namespace> [--snapshot <name> | --latest] [flags]
86+
```
87+
88+
**Flags:**
89+
- `--snapshot, -s` - Name of snapshot to restore (mutually exclusive with --latest)
90+
- `--latest` - Restore from the most recent snapshot (mutually exclusive with --snapshot)
91+
- `--background` - Run restore in background without waiting for completion
92+
- `--yes, -y` - Skip confirmation prompt
93+
94+
**Note**: Either `--snapshot` or `--latest` must be specified (mutually exclusive).
95+
96+
#### check-and-finalize
97+
98+
Check the status of a restore operation and finalize if complete.
99+
100+
```bash
101+
sts-backup elasticsearch check-and-finalize --namespace <namespace> --operation-id <snapshot> [--wait]
86102
```
87103

88104
**Flags:**
89-
- `--snapshot-name, -s` - Name of snapshot to restore (required)
90-
- `--drop-all-indices, -r` - Delete all existing STS indices before restore
91-
- `--yes` - Skip confirmation prompt
105+
- `--operation-id` - Operation ID of the restore operation (snapshot name) (required)
106+
- `--wait` - Wait for restore to complete if still running
107+
108+
**Use Case**: This command is useful when a restore was started with `--background` flag or was interrupted (Ctrl+C).
92109

93110
### stackgraph
94111

@@ -183,6 +200,90 @@ sts-backup victoriametrics check-and-finalize --namespace <namespace> --job <job
183200
**Use Case**: This command is useful when a restore job was started with `--background` flag or was interrupted (
184201
Ctrl+C).
185202

203+
### settings
204+
205+
Manage Settings backups and restores.
206+
207+
#### list
208+
209+
List available Settings backups from S3/Minio.
210+
211+
```bash
212+
sts-backup settings list --namespace <namespace>
213+
```
214+
215+
#### restore
216+
217+
Restore Settings from a backup archive. Automatically scales down affected deployments before restore and scales them
218+
back up afterward.
219+
220+
```bash
221+
sts-backup settings restore --namespace <namespace> [--archive <name> | --latest] [flags]
222+
```
223+
224+
**Flags:**
225+
226+
- `--archive` - Specific archive name to restore (e.g., sts-backup-20251117-1404.sty)
227+
- `--latest` - Restore from the most recent backup
228+
- `--background` - Run restore job in background without waiting for completion
229+
- `--yes, -y` - Skip confirmation prompt
230+
231+
**Note**: Either `--archive` or `--latest` must be specified (mutually exclusive).
232+
233+
#### check-and-finalize
234+
235+
Check the status of a background Settings restore job and clean up resources.
236+
237+
```bash
238+
sts-backup settings check-and-finalize --namespace <namespace> --job <job-name> [--wait]
239+
```
240+
241+
**Flags:**
242+
243+
- `--job, -j` - Settings restore job name (required)
244+
- `--wait, -w` - Wait for job to complete before cleanup
245+
246+
**Use Case**: This command is useful when a restore job was started with `--background` flag or was interrupted (
247+
Ctrl+C).
248+
249+
### clickhouse
250+
251+
Manage ClickHouse backups and restores.
252+
253+
#### list
254+
255+
List available ClickHouse backups from the backup API.
256+
257+
```bash
258+
sts-backup clickhouse list --namespace <namespace>
259+
```
260+
261+
#### restore
262+
263+
Restore ClickHouse from a backup. Automatically scales down affected StatefulSets before restore and scales them back up afterward.
264+
265+
```bash
266+
sts-backup clickhouse restore --namespace <namespace> --backup-name <name> [flags]
267+
```
268+
269+
**Flags:**
270+
- `--backup-name` - Name of the backup to restore (required)
271+
- `--wait` - Wait for restore to complete (default: true)
272+
273+
#### check-and-finalize
274+
275+
Check the status of a ClickHouse restore operation and finalize if complete.
276+
277+
```bash
278+
sts-backup clickhouse check-and-finalize --namespace <namespace> --operation-id <id> [--wait]
279+
```
280+
281+
**Flags:**
282+
- `--operation-id` - Operation ID of the restore operation (required)
283+
- `--wait` - Wait for restore to complete if still running
284+
285+
**Use Case**: This command is useful when checking the status of a restore operation or finalizing after completion.
286+
186287
## Configuration
187288

188289
The CLI uses configuration from Kubernetes ConfigMaps and Secrets with the following precedence:
@@ -258,13 +359,22 @@ See [internal/foundation/config/testdata/validConfigMapConfig.yaml](internal/fou
258359
│ ├── elasticsearch/ # Elasticsearch subcommands
259360
│ │ ├── configure.go # Configure snapshot repository
260361
│ │ ├── list-indices.go # List indices
261-
│ │ ├── list-snapshots.go # List snapshots
262-
│ │ └── restore-snapshot.go # Restore snapshot
362+
│ │ ├── list.go # List snapshots
363+
│ │ ├── restore.go # Restore snapshot
364+
│ │ └── check-and-finalize.go # Check and finalize restore
365+
│ ├── clickhouse/ # ClickHouse subcommands
366+
│ │ ├── list.go # List backups
367+
│ │ ├── restore.go # Restore backup
368+
│ │ └── check-and-finalize.go # Check and finalize restore
263369
│ ├── stackgraph/ # Stackgraph subcommands
264370
│ │ ├── list.go # List backups
265371
│ │ ├── restore.go # Restore backup
266372
│ │ └── check-and-finalize.go # Check and finalize restore job
267-
│ └── victoriametrics/ # VictoriaMetrics subcommands
373+
│ ├── victoriametrics/ # VictoriaMetrics subcommands
374+
│ │ ├── list.go # List backups
375+
│ │ ├── restore.go # Restore backup
376+
│ │ └── check-and-finalize.go # Check and finalize restore job
377+
│ └── settings/ # Settings subcommands
268378
│ ├── list.go # List backups
269379
│ ├── restore.go # Restore backup
270380
│ └── check-and-finalize.go # Check and finalize restore job
@@ -276,6 +386,7 @@ See [internal/foundation/config/testdata/validConfigMapConfig.yaml](internal/fou
276386
│ ├── clients/ # Layer 1: Service clients
277387
│ │ ├── k8s/ # Kubernetes client
278388
│ │ ├── elasticsearch/ # Elasticsearch client
389+
│ │ ├── clickhouse/ # ClickHouse client
279390
│ │ └── s3/ # S3/Minio client
280391
│ ├── orchestration/ # Layer 2: Workflows
281392
│ │ ├── portforward/ # Port-forwarding lifecycle

0 commit comments

Comments
 (0)