diff --git a/pitr/cli/internal/cmd/backup.go b/pitr/cli/internal/cmd/backup.go index 649cfcaf..45d292cb 100644 --- a/pitr/cli/internal/cmd/backup.go +++ b/pitr/cli/internal/cmd/backup.go @@ -161,6 +161,14 @@ func backup() error { return xerr.NewCliErr(fmt.Sprintf("check disk space failed. err: %s", err)) } + prompt := fmt.Sprintf( + "Please Check All Nodes Disk Space, Make Sure Have Enough Space To Backup Or Restore Data.\n" + + "Are you sure to continue? (Y/N)") + err = getUserApproveInTerminal(prompt) + if err != nil { + return xerr.NewCliErr(fmt.Sprintf("%s", err)) + } + // Step5. send backup command to agent-server. logging.Info("Starting backup ...") err = execBackup(lsBackup) diff --git a/pitr/cli/internal/cmd/delete.go b/pitr/cli/internal/cmd/delete.go index 61070974..caf88e65 100644 --- a/pitr/cli/internal/cmd/delete.go +++ b/pitr/cli/internal/cmd/delete.go @@ -103,6 +103,14 @@ func deleteRecord() error { return xerr.NewCliErr("one or more agent server are not available.") } + prompt := fmt.Sprintf( + "The backup record(ID: %s, CSN: %s) will be deleted forever.\n"+ + "Are you sure to continue? (Y/N)", bak.Info.ID, bak.Info.CSN) + err = getUserApproveInTerminal(prompt) + if err != nil { + return xerr.NewCliErr(fmt.Sprintf("%s", err)) + } + // mark the target backup record to be deleted // meanwhile this record cannot be restored if err := ls.HideByName(bak.Info.FileName); err != nil { diff --git a/pitr/cli/internal/cmd/delete_test.go b/pitr/cli/internal/cmd/delete_test.go index 194e6177..bbec0ca0 100644 --- a/pitr/cli/internal/cmd/delete_test.go +++ b/pitr/cli/internal/cmd/delete_test.go @@ -75,6 +75,9 @@ var _ = Describe("test delete", func() { monkey.Patch(pkg.NewLocalStorage, func(rootDir string) (pkg.ILocalStorage, error) { return ls, nil }) + monkey.Patch(getUserApproveInTerminal, func(_ string) error { + return nil + }) }) AfterEach(func() { @@ -92,7 +95,6 @@ var _ = Describe("test delete", func() { ls.EXPECT().HideByName(bak.Info.FileName).Return(nil) as.EXPECT().DeleteBackup(gomock.Any()).Return(nil) ls.EXPECT().DeleteByHidedName(bak.Info.FileName).Return(nil) - Expect(deleteRecord()).To(BeNil()) }) diff --git a/pitr/cli/internal/cmd/restore.go b/pitr/cli/internal/cmd/restore.go index 3289f3d5..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() { diff --git a/pitr/cli/internal/cmd/root.go b/pitr/cli/internal/cmd/root.go index e7e95abe..6f0e5a38 100644 --- a/pitr/cli/internal/cmd/root.go +++ b/pitr/cli/internal/cmd/root.go @@ -179,8 +179,5 @@ func checkDiskSpace(lsBackup *model.LsBackup) error { t.AppendSeparator() } t.Render() - prompt := fmt.Sprintf( - "Please Check All Nodes Disk Space, Make Sure Have Enough Space To Backup Or Restore Data.\n" + - "Are you sure to continue? (Y/N)") - return getUserApproveInTerminal(prompt) + return nil } diff --git a/pitr/cli/internal/pkg/local-storage.go b/pitr/cli/internal/pkg/local-storage.go index 47693a28..fa8a1d4b 100644 --- a/pitr/cli/internal/pkg/local-storage.go +++ b/pitr/cli/internal/pkg/local-storage.go @@ -144,6 +144,9 @@ func (ls *localStorage) ReadAll() ([]*model.LsBackup, error) { if entry.IsDir() { continue } + if strings.HasPrefix(entry.Name(), ".") { + continue + } info, err := entry.Info() if errors.Is(err, os.ErrNotExist) {