This is an automated email from the ASF dual-hosted git repository.

miaoliyao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/shardingsphere-on-cloud.git


The following commit(s) were added to refs/heads/main by this push:
     new 7207489  feat(pitr):agent server,show backup list (#230)
7207489 is described below

commit 72074892724575706472232f7b16c706071b48bf
Author: lltgo <[email protected]>
AuthorDate: Mon Feb 27 16:09:35 2023 +0800

    feat(pitr):agent server,show backup list (#230)
---
 pitr/agent/internal/pkg/opengauss.go      | 27 +++++++++++++++++++++++++++
 pitr/agent/internal/pkg/opengauss_test.go | 19 +++++++++++++++++++
 2 files changed, 46 insertions(+)

diff --git a/pitr/agent/internal/pkg/opengauss.go 
b/pitr/agent/internal/pkg/opengauss.go
index d6311ce..21d363c 100644
--- a/pitr/agent/internal/pkg/opengauss.go
+++ b/pitr/agent/internal/pkg/opengauss.go
@@ -49,6 +49,8 @@ const (
 
        _startOpenGaussFmt = "gs_ctl start --pgdata=%s"
        _stopOpenGaussFmt  = "gs_ctl stop --pgdata=%s"
+
+       _showListFmt = "gs_probackup show --instance=%s --backup-path=%s 
--format=json 2>&1"
 )
 
 func (og *openGauss) AsyncBackup(backupPath, instanceName, backupMode, pgData 
string) (string, error) {
@@ -202,6 +204,31 @@ func (og *openGauss) Restore(backupPath, instance, 
backupID, pgData string) erro
        return nil
 }
 
+func (og *openGauss) ShowBackupList(backupPath, instanceName string) 
([]model.Backup, error) {
+       cmd := fmt.Sprintf(_showListFmt, instanceName, backupPath)
+       output, err := cmds.Exec(og.shell, cmd)
+       if err != nil {
+               return nil, fmt.Errorf("cmds.Exec[shell=%s,cmd=%s] return 
err=%w", og.shell, cmd, err)
+       }
+
+       var list []model.BackupList
+       if err = json.Unmarshal([]byte(output), &list); err != nil {
+               return nil, fmt.Errorf("json.Unmarshal[output=%s] return 
err=%s,wrap=%w", output, err, cons.Internal)
+       }
+
+       for _, ins := range list {
+               if ins.Instance == instanceName {
+                       if len(ins.List) == 0 {
+                               return nil, 
fmt.Errorf("instance[name=%s],backupList[v=%+v],err=%w", ins.Instance, list, 
cons.DataNotFound)
+                       }
+
+                       return ins.List, nil
+               }
+       }
+
+       return nil, fmt.Errorf("backupList[v=%+v],err=%w", list, 
cons.DataNotFound)
+}
+
 func (og *openGauss) ignore(outputs chan *cmds.Output) {
        defer func() {
                _ = recover()
diff --git a/pitr/agent/internal/pkg/opengauss_test.go 
b/pitr/agent/internal/pkg/opengauss_test.go
index ee451b7..7bdb724 100644
--- a/pitr/agent/internal/pkg/opengauss_test.go
+++ b/pitr/agent/internal/pkg/opengauss_test.go
@@ -18,6 +18,7 @@
 package pkg
 
 import (
+       "encoding/json"
        "errors"
        "fmt"
        "time"
@@ -159,4 +160,22 @@ var _ = Describe("OpenGauss,requires opengauss 
environment", func() {
                        Expect(err).To(BeNil())
                })
        })
+
+       Context("ShowBackupList", func() {
+               It("manual:show all backup ", func() {
+                       og := &openGauss{
+                               shell: "/bin/sh",
+                       }
+
+                       var (
+                               backupPath = "/home/omm/data"
+                               instance   = "ins-default-0"
+                       )
+                       list, err := og.ShowBackupList(backupPath, instance)
+
+                       indent, err := json.MarshalIndent(list, "", "  ")
+                       Expect(err).To(BeNil())
+                       fmt.Println(string(indent))
+               })
+       })
 })

Reply via email to