-
Notifications
You must be signed in to change notification settings - Fork 116
PBM-1600 - Interactive confirm prompt when restore #1180
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
base: dev
Are you sure you want to change the base?
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -49,6 +49,7 @@ type restoreOpts struct { | |||||
| nsFrom string | ||||||
| nsTo string | ||||||
| usersAndRoles bool | ||||||
| confirmYes bool | ||||||
| rsMap string | ||||||
| conf string | ||||||
| ts string | ||||||
|
|
@@ -92,10 +93,9 @@ No other pbm command is available while the restore is running! | |||||
| `, | ||||||
| r.Snapshot, r.Name) | ||||||
| } | ||||||
| return fmt.Sprintf("Restore of the snapshot from '%s' has started", r.Snapshot) | ||||||
| return fmt.Sprintf("\nRestore of the snapshot from '%s' has started", r.Snapshot) | ||||||
| case r.PITR != "": | ||||||
| return fmt.Sprintf("Restore to the point in time '%s' has started", r.PITR) | ||||||
|
|
||||||
| return fmt.Sprintf("\nRestore to the point in time '%s' has started", r.PITR) | ||||||
| default: | ||||||
| return "" | ||||||
| } | ||||||
|
|
@@ -494,11 +494,6 @@ func doRestore( | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| err = sendCmd(ctx, conn, cmd) | ||||||
| if err != nil { | ||||||
| return nil, errors.Wrap(err, "send command") | ||||||
| } | ||||||
|
|
||||||
| if outf != outText { | ||||||
| return &restore.RestoreMeta{ | ||||||
| Name: name, | ||||||
|
|
@@ -518,7 +513,23 @@ func doRestore( | |||||
| if o.pitr != "" { | ||||||
| pitrs = fmt.Sprintf(" to point-in-time %s", o.pitr) | ||||||
| } | ||||||
| fmt.Printf("Starting restore %s%s%s", name, pitrs, bcpName) | ||||||
|
|
||||||
| fmt.Println("Restore:") | ||||||
| fmt.Printf(" - %s%s%s\n", name, pitrs, bcpName) | ||||||
|
|
||||||
| if !o.confirmYes { | ||||||
| err := util.AskConfirmation("Are you sure you want to restore this backup?") | ||||||
| if err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| err = sendCmd(ctx, conn, cmd) | ||||||
| if err != nil { | ||||||
| return nil, errors.Wrap(err, "send command") | ||||||
| } | ||||||
|
|
||||||
| fmt.Printf("Starting restore") | ||||||
|
||||||
| fmt.Printf("Starting restore") | |
| fmt.Printf("Starting restore: %s%s%s\n", name, pitrs, bcpName) |
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.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package util | ||
|
|
||
| import ( | ||
| "bufio" | ||
| "fmt" | ||
| "os" | ||
| "strings" | ||
|
|
||
| "github.com/percona/percona-backup-mongodb/pbm/errors" | ||
| ) | ||
|
|
||
| func AskConfirmation(question string) error { | ||
| fi, err := os.Stdin.Stat() | ||
| if err != nil { | ||
| return errors.Wrap(err, "stat stdin") | ||
| } | ||
| if (fi.Mode() & os.ModeCharDevice) == 0 { | ||
| return errors.New("no tty") | ||
| } | ||
|
|
||
| fmt.Printf("%s [y/N] ", question) | ||
|
|
||
| scanner := bufio.NewScanner(os.Stdin) | ||
| scanner.Scan() | ||
| if err := scanner.Err(); err != nil { | ||
| return errors.Wrap(err, "read stdin") | ||
| } | ||
|
|
||
| switch strings.TrimSpace(scanner.Text()) { | ||
| case "yes", "Yes", "YES", "Y", "y": | ||
| return nil | ||
| } | ||
|
|
||
| return errors.ErrUserCanceled | ||
| } |
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.
The confirmYes field is added to the struct but there's no visible command-line flag definition or initialization code in this diff. Ensure that a corresponding CLI flag (like --yes or --confirm) is properly defined and wired to this field.
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 is a good point. Same as with delete, user should be able to do inline confirmation
pbm restore <bcp> -yand then there should not be a prompt. It essential for scripts.