fix restore command to match README documentation#471
fix restore command to match README documentation#471youngminz wants to merge 1 commit intodatabacker:masterfrom
Conversation
Signed-off-by: Youngmin Koo <youngminz.kr@gmail.com>
| } | ||
|
|
||
| // Always pass empty targetFile to use the full path from the URL | ||
| targetFile := "" |
There was a problem hiding this comment.
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.
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.
deitch
left a comment
There was a problem hiding this comment.
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.
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.
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 { |
| // 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.
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.
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
restorecommand to work exactly as documented in README.md, resolving the "requires at least 1 arg(s)" error and S3 path handling issues.Problem
The
restorecommand implementation didn't match README documentation:Solution
Simplified and fixed the restore command:
--targetflag, orDB_RESTORE_TARGETenvironment 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
restorecommand requires argument but README shows none #470 - "requires at least 1 arg(s)" error