Skip to content

Commit

Permalink
fix(cmd/influx): accept --input flag in restore command (#21477)
Browse files Browse the repository at this point in the history
* feat(cmd/influx): accept --input flag in `restore` command.
* fix(restore): make it an error if no backup manifests are found
  • Loading branch information
danxmoran committed May 14, 2021
1 parent d89b9cb commit 6bdcbaa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
1. [21356](https://github.com/influxdata/influxdb/pull/21356): Disable MergeFiltersRule until it is more stable.
1. [21369](https://github.com/influxdata/influxdb/pull/21369): Add limits to the `/api/v2/delete` endpoint for start and stop times with error messages.
1. [21375](https://github.com/influxdata/influxdb/pull/21375): Add logging to NATS streaming server to help debug startup failures.
1. [21477](https://github.com/influxdata/influxdb/pull/21477): Accept `--input` instead of a positional arg in `influx restore`.
1. [21477](https://github.com/influxdata/influxdb/pull/21477): Print error instead of panicking when `influx restore` fails to find backup manifests.

## v2.0.6 [2021-04-29]

Expand Down
16 changes: 13 additions & 3 deletions cmd/influx/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"errors"
"fmt"
"os"

Expand Down Expand Up @@ -46,13 +47,22 @@ func (b *cmdRestoreBuilder) cmdRestore() *cobra.Command {
cmd.Flags().StringVarP(&b.bucketName, "bucket", "b", "", "The name of the bucket to restore")
cmd.Flags().StringVar(&b.newBucketName, "new-bucket", "", "The name of the bucket to restore to")
cmd.Flags().StringVar(&b.newOrgName, "new-org", "", "The name of the organization to restore to")
cmd.Flags().StringVar(&b.path, "input", "", "Local backup data path (required)")
cmd.Flags().StringVar(&b.path, "input", "", "Local backup data path")
cmd.Flags().MarkDeprecated("input", "pass backup data path as a positional argument instead")
cmd.Use = "restore [flags] path"
cmd.Args = func(cmd *cobra.Command, args []string) error {
// Legacy: path set by --input flag.
if b.path != "" {
if len(args) != 0 {
return errors.New("cannot specify backup directory using both --input and a positional argument")
}
return nil
}

if len(args) == 0 {
return fmt.Errorf("must specify path to backup directory")
return errors.New("must specify path to backup directory")
} else if len(args) > 1 {
return fmt.Errorf("too many args specified")
return errors.New("only one backup directory can be specified at a time")
}
b.path = args[0]
return nil
Expand Down
2 changes: 1 addition & 1 deletion restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (r *restoreRunner) loadManifests(path string) error {
if err != nil {
return fmt.Errorf("failed to find backup manifests at %q: %w", path, err)
} else if len(manifests) == 0 {
return nil
return fmt.Errorf("no backup manifests found at %q", path)
}
sort.Sort(sort.Reverse(sort.StringSlice(manifests)))

Expand Down

0 comments on commit 6bdcbaa

Please sign in to comment.