-
Notifications
You must be signed in to change notification settings - Fork 209
fix restore command to match README documentation #471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,7 @@ func restoreCmd(passedExecs execs, cmdConfig *cmdConfiguration) (*cobra.Command, | |
| PreRun: func(cmd *cobra.Command, args []string) { | ||
| bindFlags(cmd, v) | ||
| }, | ||
| Args: cobra.MinimumNArgs(1), | ||
| Args: cobra.RangeArgs(0, 1), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| cmdConfig.logger.Debug("starting restore") | ||
| ctx := context.Background() | ||
|
|
@@ -40,8 +40,20 @@ func restoreCmd(passedExecs execs, cmdConfig *cmdConfiguration) (*cobra.Command, | |
| }() | ||
| ctx = util.ContextWithTracer(ctx, tracer) | ||
| _, startupSpan := tracer.Start(ctx, "startup") | ||
| targetFile := args[0] | ||
| target := v.GetString("target") | ||
|
|
||
| // Get target from args[0], --target flag, or DB_RESTORE_TARGET environment variable | ||
| var target string | ||
| if len(args) > 0 { | ||
| target = args[0] | ||
| } else { | ||
| target = v.GetString("target") | ||
| } | ||
| if target == "" { | ||
| return fmt.Errorf("target must be specified as argument, --target flag, or DB_RESTORE_TARGET environment variable") | ||
| } | ||
|
|
||
| // Always pass empty targetFile to use the full path from the URL | ||
| targetFile := "" | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of just setting
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will not exactly work. The "target" really is the store, or location, while the "file" is the path in that location. The fact that you specify it as a single string is a convenience for the Which means that for this to work, you likely will need to separate the single URL into the two parts, file and store. |
||
| // get databases namesand mappings | ||
| databasesMap := make(map[string]string) | ||
| databases := strings.TrimSpace(v.GetString("database")) | ||
|
|
@@ -144,9 +156,6 @@ func restoreCmd(passedExecs execs, cmdConfig *cmdConfiguration) (*cobra.Command, | |
|
|
||
| flags := cmd.Flags() | ||
| flags.String("target", "", "full URL target to the backup that you wish to restore") | ||
| if err := cmd.MarkFlagRequired("target"); err != nil { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call here. |
||
| return nil, err | ||
| } | ||
|
|
||
| // compression | ||
| flags.String("compression", defaultCompression, "Compression to use. Supported are: `gzip`, `bzip2`, `none`") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,7 +73,15 @@ func (s *S3) Pull(ctx context.Context, source, target string, logger *log.Entry) | |
| return 0, fmt.Errorf("failed to get AWS client: %v", err) | ||
| } | ||
|
|
||
| bucket, path := s.url.Hostname(), path.Join(s.url.Path, source) | ||
| bucket := s.url.Hostname() | ||
| // If source is empty, use the path from URL directly (for restore command) | ||
| // Otherwise, append source to the URL path (for dump command) | ||
| var objectPath string | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call on cleaning up the overload of |
||
| if source == "" { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We had some issues a while back with the pathing of objects, that was cleaned up (I could find the PR+commit, if needed). Maybe something still lingers. It would help if you can explain what combinations trigger the error? |
||
| objectPath = strings.TrimPrefix(s.url.Path, "/") | ||
| } else { | ||
| objectPath = strings.TrimPrefix(path.Join(s.url.Path, source), "/") | ||
| } | ||
|
|
||
| // Create a downloader with the session and default options | ||
| downloader := manager.NewDownloader(client) | ||
|
|
@@ -88,7 +96,7 @@ func (s *S3) Pull(ctx context.Context, source, target string, logger *log.Entry) | |
| // Write the contents of S3 Object to the file | ||
| n, err := downloader.Download(context.TODO(), f, &s3.GetObjectInput{ | ||
| Bucket: aws.String(bucket), | ||
| Key: aws.String(path), | ||
| Key: aws.String(objectPath), | ||
| }) | ||
| if err != nil { | ||
| return 0, fmt.Errorf("failed to download file, %v", err) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change this order? The priority should be CLI flag over command line positional option over env var. I know the positional one is weird, but it has a long history, so I am hesitant to remove it.