-
Notifications
You must be signed in to change notification settings - Fork 205
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
Conversation
Signed-off-by: Youngmin Koo <[email protected]>
} | ||
|
||
// Always pass empty targetFile to use the full path from the URL | ||
targetFile := "" |
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.
Instead of just setting targetFile := ""
and passing empty strings around, should we completely remove the TargetFile
field from the entire codebase?
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.
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 restore
. Look at how dump
works.
Which means that for this to work, you likely will need to separate the single URL into the two parts, file and store.
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.
Thanks for this PR to clean things up; it is much appreciated.
I had a small change request in the priority for setting the target. You will need to have target and file within target as separate things to pass.
Lastly, cases for the s3 would help understand the issue.
|
||
// Get target from args[0], --target flag, or DB_RESTORE_TARGET environment variable | ||
var target string | ||
if len(args) > 0 { |
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.
} | ||
|
||
// Always pass empty targetFile to use the full path from the URL | ||
targetFile := "" |
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.
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 restore
. Look at how dump
works.
Which means that for this to work, you likely will need to separate the single URL into the two parts, file and store.
|
||
flags := cmd.Flags() | ||
flags.String("target", "", "full URL target to the backup that you wish to restore") | ||
if err := cmd.MarkFlagRequired("target"); err != nil { |
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.
Good call here.
// 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 | ||
if source == "" { |
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.
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?
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 |
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.
Good call on cleaning up the overload of path
@deitch Thank you for the detailed review. After understanding the architectural design (separation of target/store and file), I realize my changes would break the existing interface - which feels too risky for a mature project with a long history. I'd like to close this PR and create a new one that only updates the README.md to match the current behavior. This would fix #470 without any breaking changes. Would a documentation-only PR be acceptable? I think it's a safer approach. Thanks for helping me understand the project better! |
Definitely. And it would be appreciated too. |
Description
This PR fixes the
restore
command to work exactly as documented in README.md, resolving the "requires at least 1 arg(s)" error and S3 path handling issues.Problem
The
restore
command implementation didn't match README documentation:Solution
Simplified and fixed the restore command:
--target
flag, orDB_RESTORE_TARGET
environment variableCode changes:
cmd/restore.go
: Simplified target resolution logicpkg/storage/s3/s3.go
: Fixed path handling when source is emptySupported Usage Patterns
All three methods now work correctly:
Testing
Tested successfully with both S3 and local files:
S3 Tests
Local File Tests
Error Handling
Fixes
restore
command requires argument but README shows none #470 - "requires at least 1 arg(s)" error