From 24008fb2dd1c9f7f5f80e8d35054dd8808aecb87 Mon Sep 17 00:00:00 2001 From: mwdmwd Date: Mon, 11 Nov 2024 01:32:44 +0100 Subject: [PATCH 1/3] feat: influx_inspect export from a single tsm file --- cmd/influx_inspect/export/export.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmd/influx_inspect/export/export.go b/cmd/influx_inspect/export/export.go index 0906f02af9b..bf26a3f6230 100644 --- a/cmd/influx_inspect/export/export.go +++ b/cmd/influx_inspect/export/export.go @@ -33,6 +33,7 @@ type Command struct { out string database string retentionPolicy string + tsmFile string startTime int64 endTime int64 compress bool @@ -71,6 +72,7 @@ func (cmd *Command) Run(args ...string) error { fs.StringVar(&cmd.out, "out", os.Getenv("HOME")+"/.influxdb/export", "'-' for standard out or the destination file to export to") fs.StringVar(&cmd.database, "database", "", "Optional: the database to export") fs.StringVar(&cmd.retentionPolicy, "retention", "", "Optional: the retention policy to export (requires -database)") + fs.StringVar(&cmd.tsmFile, "tsmfile", "", "Optional: path to a single tsm file to export (requires -database and -retention") fs.StringVar(&start, "start", "", "Optional: the start time to export (RFC3339 format)") fs.StringVar(&end, "end", "", "Optional: the end time to export (RFC3339 format)") fs.BoolVar(&cmd.lponly, "lponly", false, "Only export line protocol") @@ -119,6 +121,9 @@ func (cmd *Command) validate() error { if cmd.retentionPolicy != "" && cmd.database == "" { return fmt.Errorf("must specify a db") } + if cmd.tsmFile != "" && (cmd.database == "" || cmd.retentionPolicy == "") { + return fmt.Errorf("must specify a db and retention policy") + } if cmd.startTime != 0 && cmd.endTime != 0 && cmd.endTime < cmd.startTime { return fmt.Errorf("end time before start time") } @@ -126,6 +131,13 @@ func (cmd *Command) validate() error { } func (cmd *Command) export() error { + if cmd.tsmFile != "" { + key := cmd.database + string(os.PathSeparator) + cmd.retentionPolicy + cmd.manifest[key] = struct{}{} + cmd.tsmFiles[key] = []string{cmd.tsmFile} + return cmd.write() + } + if err := cmd.walkTSMFiles(); err != nil { return err } From 49ea971211db904520ae2a5c664326e6e79a935a Mon Sep 17 00:00:00 2001 From: mwdmwd Date: Sat, 11 Jan 2025 04:53:54 +0100 Subject: [PATCH 2/3] fix: improve error message for -tsmfile --- cmd/influx_inspect/export/export.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/influx_inspect/export/export.go b/cmd/influx_inspect/export/export.go index bf26a3f6230..00875135ade 100644 --- a/cmd/influx_inspect/export/export.go +++ b/cmd/influx_inspect/export/export.go @@ -122,7 +122,7 @@ func (cmd *Command) validate() error { return fmt.Errorf("must specify a db") } if cmd.tsmFile != "" && (cmd.database == "" || cmd.retentionPolicy == "") { - return fmt.Errorf("must specify a db and retention policy") + return fmt.Errorf("must specify a db (-database) and retention policy (-retention)") } if cmd.startTime != 0 && cmd.endTime != 0 && cmd.endTime < cmd.startTime { return fmt.Errorf("end time before start time") From 1827ab1ba5f9252bf0d5d7a74ff653ace9f952b3 Mon Sep 17 00:00:00 2001 From: mwdmwd Date: Sat, 11 Jan 2025 04:55:53 +0100 Subject: [PATCH 3/3] fix: make error for RP without DB consistent --- cmd/influx_inspect/export/export.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/influx_inspect/export/export.go b/cmd/influx_inspect/export/export.go index 00875135ade..4960e248da4 100644 --- a/cmd/influx_inspect/export/export.go +++ b/cmd/influx_inspect/export/export.go @@ -119,7 +119,7 @@ func (cmd *Command) Run(args ...string) error { func (cmd *Command) validate() error { if cmd.retentionPolicy != "" && cmd.database == "" { - return fmt.Errorf("must specify a db") + return fmt.Errorf("must specify a db (-database)") } if cmd.tsmFile != "" && (cmd.database == "" || cmd.retentionPolicy == "") { return fmt.Errorf("must specify a db (-database) and retention policy (-retention)")