From 7999835ac39fe9e197dd1c8024b1cd52cd3fca31 Mon Sep 17 00:00:00 2001 From: mwdmwd <66176893+mwdmwd@users.noreply.github.com> Date: Mon, 13 Jan 2025 20:48:35 +0100 Subject: [PATCH] feat: influx_inspect export from a single tsm file (#25530) * feat: This PR adds -tsm file flag to export Adds the ability to use influx_inspect export to export data from a single tsm file, for example influx_inspect export -out - -tsmfile 000000006-000000002.tsm.bad -database thermo -retention autogen. --- cmd/influx_inspect/export/export.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cmd/influx_inspect/export/export.go b/cmd/influx_inspect/export/export.go index 0906f02af9b..4960e248da4 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") @@ -117,7 +119,10 @@ 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)") } 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 }