Skip to content

Commit 638548c

Browse files
authored
Merge pull request #1453 from Altinity/feature_tables_parts_and_partitions
add --list-parts and --list-partitions to tables command,
2 parents 5b0337c + 9d13b0c commit 638548c

10 files changed

Lines changed: 566 additions & 53 deletions

File tree

Manual.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@ NAME:
44
clickhouse-backup tables - List of tables, exclude skip_tables
55
66
USAGE:
7-
clickhouse-backup tables [--tables=<db>.<table>] [--remote-backup=<backup-name>] [--local-backup=<backup-name>] [-f, --format=<text|json|yaml|csv|tsv>] [--all]
7+
clickhouse-backup tables [--tables=<db>.<table>] [--remote-backup=<backup-name>] [--local-backup=<backup-name>] [-f, --format=<text|json|yaml|csv|tsv>] [--all] [--parts] [--partitions]
88
99
OPTIONS:
10-
--config value, -c value Config 'FILE' name. (default: "/etc/clickhouse-backup/config.yml") [$CLICKHOUSE_BACKUP_CONFIG]
11-
--environment-override value, --env value override any environment variable via CLI parameter
12-
--all, -a Print table even when match with skip_tables pattern
13-
--table value, --tables value, -t value List tables only match with table name patterns, separated by comma, allow ? and * as wildcard
14-
--remote-backup value List tables from a remote backup, including per-table size and parts count
15-
--local-backup value List tables from a local backup (read from disk, no live ClickHouse query), including per-table size and parts count
16-
--format value, -f value Output format (text|json|yaml|csv|tsv)
10+
--config value, -c value Config 'FILE' name. (default: "/etc/clickhouse-backup/config.yml") [$CLICKHOUSE_BACKUP_CONFIG]
11+
--environment-override value, --env value override any environment variable via CLI parameter
12+
--all, -a Print table even when match with skip_tables pattern
13+
--table value, --tables value, -t value List tables only match with table name patterns, separated by comma, allow ? and * as wildcard
14+
--remote-backup value List tables from a remote backup, including per-table size and parts count
15+
--local-backup value List tables from a local backup (read from disk, no live ClickHouse query), including per-table size and parts count
16+
--format value, -f value Output format (text|json|yaml|csv|tsv)
17+
--parts system.parts, --list-parts system.parts Also list every physical part for each table (name, partition_id, size)
18+
Against the live server, reads name/partition_id/bytes_on_disk from system.parts
19+
Against --local-backup/--remote-backup, reads part names from backup metadata (partition_id derived from the name, no size available)
20+
--partitions system.parts, --list-partitions system.parts Also list the distinct partitions for each table (partition_id, partition, parts count, size), aggregated from parts
21+
Against the live server, reads partition_id/partition/parts/size from system.parts
22+
Against --local-backup/--remote-backup, derives partition_id and parts count from part names (no partition value or per-partition size available)
1723
1824
```
1925
### CLI command - create
@@ -208,6 +214,7 @@ Look at the system.parts partition and partition_id fields for details https://c
208214
--restore-schema-as-attach Use DETACH/ATTACH instead of DROP/CREATE for schema restoration
209215
--replicated-copy-to-detached Copy data to detached folder for Replicated*MergeTree tables but skip ATTACH PART step
210216
--skip-empty-tables Skip restoring tables that have no data (empty tables with only schema)
217+
--rebind-replica-path-if-exists Override clickhouse.rebind_replica_path_if_exists, rebind a restored ReplicatedMergeTree to default_replica_path when the original ZK path still has leftover state but our replica entry is absent
211218
212219
```
213220
### CLI command - restore_remote
@@ -246,6 +253,7 @@ Look at the system.parts partition and partition_id fields for details https://c
246253
--restore-schema-as-attach Use DETACH/ATTACH instead of DROP/CREATE for schema restoration
247254
--hardlink-exists-files Create hardlinks for existing files instead of downloading
248255
--skip-empty-tables Skip restoring tables that have no data (empty tables with only schema)
256+
--rebind-replica-path-if-exists Override clickhouse.rebind_replica_path_if_exists, rebind a restored ReplicatedMergeTree to default_replica_path when the original ZK path still has leftover state but our replica entry is absent
249257
250258
```
251259
### CLI command - delete

ReadMe.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,8 @@ Print list of tables: `curl -s localhost:7171/backup/tables | jq .`, exclude pat
486486
- Optional query argument `table` works the same as the `--table=pattern` CLI argument.
487487
- Optional query argument `remote_backup` (or `remote-backup`) works the same as the `--remote-backup=name` CLI argument. The response then includes per-table `size`, `total_bytes`, `parts`, and `disks` (JSON array of disk names) fields read from the remote backup metadata.
488488
- Optional query argument `local_backup` (or `local-backup`) works the same as the `--local-backup=name` CLI argument: it lists tables from a local backup directly from disk (no live ClickHouse query required), with `size`, `total_bytes`, `parts`, and `disks` (JSON array) fields.
489+
- Optional boolean query argument `list_parts` (alias `parts`) works the same as the `--list-parts`/`--parts` CLI argument: it attaches a `parts_list` array per table (`name`, `partition_id`, and against the live server also `total_bytes`/`size`). Works standalone against the live server or together with `remote_backup`/`local_backup`; against a remote/local backup, `partition_id` is derived from the `_`-delimited prefix of each part's name (no size available there).
490+
- Optional boolean query argument `partitions` (alias `list_partitions`) works the same as the `--partitions`/`--list-partitions` CLI argument: it attaches a `partitions` array per table (`partition_id`, and against the live server also `partition`/`parts`/`total_bytes`/`size`), aggregated from parts. Independent of `list_parts`; against a remote/local backup, `partition_id` is derived the same way as `list_parts` (no partition value or size available there).
489491

490492
### GET /backup/tables/all
491493

@@ -494,6 +496,7 @@ Print list of tables: `curl -s localhost:7171/backup/tables/all | jq .`, ignore
494496
- Optional query argument `table` works the same as the `--table=pattern` CLI argument.
495497
- Optional query argument `remote_backup` (or `remote-backup`) works the same as the `--remote-backup=name` CLI argument; response shape matches `GET /backup/tables` with the remote-backup parameter.
496498
- Optional query argument `local_backup` (or `local-backup`) works the same as the `--local-backup=name` CLI argument; response shape matches `GET /backup/tables` with the local-backup parameter.
499+
- Optional boolean query arguments `list_parts`/`parts` and `partitions`/`list_partitions` work the same as on `GET /backup/tables`.
497500

498501
### POST /backup/create
499502

@@ -732,16 +735,22 @@ NAME:
732735
clickhouse-backup tables - List of tables, exclude skip_tables
733736
734737
USAGE:
735-
clickhouse-backup tables [--tables=<db>.<table>] [--remote-backup=<backup-name>] [--local-backup=<backup-name>] [-f, --format=<text|json|yaml|csv|tsv>] [--all]
738+
clickhouse-backup tables [--tables=<db>.<table>] [--remote-backup=<backup-name>] [--local-backup=<backup-name>] [-f, --format=<text|json|yaml|csv|tsv>] [--all] [--parts] [--partitions]
736739
737740
OPTIONS:
738-
--config value, -c value Config 'FILE' name. (default: "/etc/clickhouse-backup/config.yml") [$CLICKHOUSE_BACKUP_CONFIG]
739-
--environment-override value, --env value override any environment variable via CLI parameter
740-
--all, -a Print table even when match with skip_tables pattern
741-
--table value, --tables value, -t value List tables only match with table name patterns, separated by comma, allow ? and * as wildcard
742-
--remote-backup value List tables from a remote backup, including per-table size and parts count
743-
--local-backup value List tables from a local backup (read from disk, no live ClickHouse query), including per-table size and parts count
744-
--format value, -f value Output format (text|json|yaml|csv|tsv)
741+
--config value, -c value Config 'FILE' name. (default: "/etc/clickhouse-backup/config.yml") [$CLICKHOUSE_BACKUP_CONFIG]
742+
--environment-override value, --env value override any environment variable via CLI parameter
743+
--all, -a Print table even when match with skip_tables pattern
744+
--table value, --tables value, -t value List tables only match with table name patterns, separated by comma, allow ? and * as wildcard
745+
--remote-backup value List tables from a remote backup, including per-table size and parts count
746+
--local-backup value List tables from a local backup (read from disk, no live ClickHouse query), including per-table size and parts count
747+
--format value, -f value Output format (text|json|yaml|csv|tsv)
748+
--parts system.parts, --list-parts system.parts Also list every physical part for each table (name, partition_id, size)
749+
Against the live server, reads name/partition_id/bytes_on_disk from system.parts
750+
Against --local-backup/--remote-backup, reads part names from backup metadata (partition_id derived from the name, no size available)
751+
--partitions system.parts, --list-partitions system.parts Also list the distinct partitions for each table (partition_id, partition, parts count, size), aggregated from parts
752+
Against the live server, reads partition_id/partition/parts/size from system.parts
753+
Against --local-backup/--remote-backup, derives partition_id and parts count from part names (no partition value or per-partition size available)
745754
746755
```
747756
### CLI command - create

cmd/clickhouse-backup/main.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ func main() {
8888
{
8989
Name: "tables",
9090
Usage: "List of tables, exclude skip_tables",
91-
UsageText: "clickhouse-backup tables [--tables=<db>.<table>] [--remote-backup=<backup-name>] [--local-backup=<backup-name>] [-f, --format=<text|json|yaml|csv|tsv>] [--all]",
91+
UsageText: "clickhouse-backup tables [--tables=<db>.<table>] [--remote-backup=<backup-name>] [--local-backup=<backup-name>] [-f, --format=<text|json|yaml|csv|tsv>] [--all] [--parts] [--partitions]",
9292
Action: func(c *cli.Context) error {
9393
b := backup.NewBackuper(config.GetConfigFromCli(c))
94-
return b.PrintTables(c.Bool("all"), c.String("table"), c.String("remote-backup"), c.String("local-backup"), c.String("format"))
94+
return b.PrintTables(c.Bool("all"), c.String("table"), c.String("remote-backup"), c.String("local-backup"), c.String("format"), c.Bool("parts"), c.Bool("partitions"))
9595
},
9696
Flags: append(cliapp.Flags,
9797
cli.BoolFlag{
@@ -119,6 +119,20 @@ func main() {
119119
Hidden: false,
120120
Usage: "Output format (text|json|yaml|csv|tsv)",
121121
},
122+
cli.BoolFlag{
123+
Name: "parts, list-parts",
124+
Hidden: false,
125+
Usage: "Also list every physical part for each table (name, partition_id, size)\n" +
126+
"Against the live server, reads name/partition_id/bytes_on_disk from `system.parts`\n" +
127+
"Against --local-backup/--remote-backup, reads part names from backup metadata (partition_id derived from the name, no size available)",
128+
},
129+
cli.BoolFlag{
130+
Name: "partitions, list-partitions",
131+
Hidden: false,
132+
Usage: "Also list the distinct partitions for each table (partition_id, partition, parts count, size), aggregated from parts\n" +
133+
"Against the live server, reads partition_id/partition/parts/size from `system.parts`\n" +
134+
"Against --local-backup/--remote-backup, derives partition_id and parts count from part names (no partition value or per-partition size available)",
135+
},
122136
),
123137
},
124138
{

generate_manual.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,32 @@ CLICKHOUSE_BACKUP_BIN=${CLICKHOUSE_BACKUP_BIN:-build/$(go env GOOS)/$(go env GOA
44
make clean "${CLICKHOUSE_BACKUP_BIN}" >&2
55

66
# Extract command list dynamically from `--help`. Skip the built-in `help, h` entry.
7+
# New commands (e.g. `rebase`) need no changes here - they're picked up automatically.
78
mapfile -t cmds < <(
89
go run ./cmd/clickhouse-backup/ --help 2>/dev/null \
910
| awk '/^COMMANDS:/{flag=1; next} /^GLOBAL OPTIONS:/{flag=0} flag && NF{print $1}' \
1011
| sed 's/,$//' \
1112
| grep -vE '^(help|h)$'
1213
)
1314

15+
manual_file=$(mktemp)
16+
trap 'rm -f "${manual_file}"' EXIT
17+
1418
for cmd in "${cmds[@]}"; do
1519
echo "### CLI command - ${cmd}"
1620
echo '```'
1721
"${CLICKHOUSE_BACKUP_BIN}" help "${cmd}"
1822
echo '```'
19-
done
23+
done > "${manual_file}"
24+
25+
cp "${manual_file}" Manual.md
26+
27+
# README.md embeds the same content under "## Common CLI Usage" - keep it in sync so the two
28+
# docs can't drift apart again.
29+
readme_tmp=$(mktemp)
30+
trap 'rm -f "${manual_file}" "${readme_tmp}"' EXIT
31+
awk '/^## Common CLI Usage$/{print; print ""; exit} {print}' README.md > "${readme_tmp}"
32+
cat "${manual_file}" >> "${readme_tmp}"
33+
mv "${readme_tmp}" README.md
34+
35+
echo "Updated Manual.md and README.md's 'Common CLI Usage' section." >&2

go.mod

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ require (
3131
github.com/kelseyhightower/envconfig v1.4.0
3232
github.com/klauspost/compress v1.19.0
3333
github.com/klauspost/pgzip v1.2.6
34-
github.com/mattn/go-shellwords v1.0.13
34+
github.com/mattn/go-shellwords v1.0.14
3535
github.com/mholt/archives v0.1.5
3636
github.com/otiai10/copy v1.14.1
3737
github.com/pkg/errors v0.9.1
@@ -51,7 +51,7 @@ require (
5151
golang.org/x/mod v0.38.0
5252
golang.org/x/sync v0.22.0
5353
golang.org/x/text v0.40.0
54-
google.golang.org/api v0.287.1
54+
google.golang.org/api v0.288.0
5555
gopkg.in/yaml.v3 v3.0.1
5656
)
5757

@@ -66,9 +66,9 @@ require (
6666
github.com/Azure/azure-sdk-for-go/sdk/internal v1.12.0 // indirect
6767
github.com/AzureAD/microsoft-authentication-library-for-go v1.7.2 // indirect
6868
github.com/ClickHouse/ch-go v0.73.0 // indirect
69-
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.33.0 // indirect
70-
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.57.0 // indirect
71-
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.57.0 // indirect
69+
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.34.0 // indirect
70+
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.58.0 // indirect
71+
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.58.0 // indirect
7272
github.com/Microsoft/go-winio v0.6.2 // indirect
7373
github.com/STARRY-S/zip v0.2.3 // indirect
7474
github.com/andybalholm/brotli v1.2.2 // indirect
@@ -137,7 +137,7 @@ require (
137137
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
138138
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
139139
github.com/prometheus/client_model v0.6.2 // indirect
140-
github.com/prometheus/common v0.69.0 // indirect
140+
github.com/prometheus/common v0.70.0 // indirect
141141
github.com/prometheus/procfs v0.21.1 // indirect
142142
github.com/russross/blackfriday/v2 v2.1.0 // indirect
143143
github.com/segmentio/asm v1.2.1 // indirect

0 commit comments

Comments
 (0)