diff --git a/pitr/cli/internal/cmd/restore.go b/pitr/cli/internal/cmd/restore.go index 8e720784..68602228 100644 --- a/pitr/cli/internal/cmd/restore.go +++ b/pitr/cli/internal/cmd/restore.go @@ -113,6 +113,15 @@ func restore() error { return xerr.NewCliErr(fmt.Sprintf("check database exist failed. err: %s", err)) } + prompt := fmt.Sprintf( + "Detected That The Database [%s] Already Exists In ShardingSphere-Proxy Metadata.\n"+ + "The Logic Database Will Be DROPPED And Then Insert Backup's Metadata Into ShardingSphere-Proxy After Restoring The Backup Data.\n"+ + "Are you sure to continue? (Y/N)", strings.Join(databaseNamesExist, ",")) + err = getUserApproveInTerminal(prompt) + if err != nil { + return xerr.NewCliErr(fmt.Sprintf("%s", err)) + } + // check agent server status logging.Info("Checking agent server status...") if available := checkAgentServerStatus(bak); !available { @@ -150,12 +159,7 @@ func checkDatabaseExist(proxy pkg.IShardingSphereProxy, bak *model.LsBackup) err return nil } - // get user input to confirm - prompt := fmt.Sprintf( - "Detected That The Database [%s] Already Exists In ShardingSphere-Proxy Metadata.\n"+ - "The Logic Database Will Be DROPPED And Then Insert Backup's Metadata Into ShardingSphere-Proxy After Restoring The Backup Data.\n"+ - "Are you sure to continue? (Y/N)", strings.Join(databaseNamesExist, ",")) - return getUserApproveInTerminal(prompt) + return nil } func restoreDataToSSProxy(proxy pkg.IShardingSphereProxy, lsBackup *model.LsBackup) error { diff --git a/pitr/cli/internal/cmd/restore_test.go b/pitr/cli/internal/cmd/restore_test.go index cfa3116c..bd28ffbb 100644 --- a/pitr/cli/internal/cmd/restore_test.go +++ b/pitr/cli/internal/cmd/restore_test.go @@ -104,6 +104,9 @@ var _ = Describe("test restore", func() { monkey.Patch(pkg.NewLocalStorage, func(rootDir string) (pkg.ILocalStorage, error) { return ls, nil }) + monkey.Patch(getUserApproveInTerminal, func(_ string) error { + return nil + }) }) AfterEach(func() { @@ -131,15 +134,6 @@ var _ = Describe("test restore", func() { Expect(restore()).To(BeNil()) }) - // test getUserApproveInTerminal - Context("test userApproveInTerminal", func() { - // test user abort - It("user abort", func() { - // exec getUserApproveInTerminal - Expect(getUserApproveInTerminal("")).To(Equal(xerr.NewCliErr("User abort"))) - }) - }) - Context("restore data to ss proxy", func() { It("no need to drop database", func() {