You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by mi...@apache.org on 2023/02/17 10:56:52 UTC
[shardingsphere-on-cloud] branch main updated: feat:add restore method and update AsyncExec func (#212)
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 f4c140d feat:add restore method and update AsyncExec func (#212)
f4c140d is described below
commit f4c140dff841a68c072e95174697a7db43ed9e92
Author: lltgo <ll...@outlook.com>
AuthorDate: Fri Feb 17 18:56:47 2023 +0800
feat:add restore method and update AsyncExec func (#212)
---
pitr/agent/internal/cons/error.go | 1 +
pitr/agent/internal/pkg/opengauss.go | 17 +++++++++++++++++
pitr/agent/pkg/cmds/cmd.go | 11 ++++++++---
3 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/pitr/agent/internal/cons/error.go b/pitr/agent/internal/cons/error.go
index 3868f65..a617dde 100644
--- a/pitr/agent/internal/cons/error.go
+++ b/pitr/agent/internal/cons/error.go
@@ -32,4 +32,5 @@ var (
InstanceNotExist = xerror.New(10007, "The instance not exist.")
StartOpenGaussFailed = xerror.New(10008, "Failed to start opengauss.")
StopOpenGaussFailed = xerror.New(10009, "Failed to stop opengauss.")
+ RestoreFailed = xerror.New(10010, "Failed to restore opengauss.")
)
diff --git a/pitr/agent/internal/pkg/opengauss.go b/pitr/agent/internal/pkg/opengauss.go
index 5437995..3cf20f9 100644
--- a/pitr/agent/internal/pkg/opengauss.go
+++ b/pitr/agent/internal/pkg/opengauss.go
@@ -38,6 +38,7 @@ const (
_backupFmt = "gs_probackup backup --backup-path=%s --instance=%s --backup-mode=%s --pgdata=%s 2>&1"
_showFmt = "gs_probackup show --instance=%s --backup-path=%s --backup-id=%s --format=json 2>&1"
_delBackupFmt = "gs_probackup delete --backup-path=%s --instance=%s --backup-id=%s 2>&1"
+ _restoreFmt = "gs_probackup restore --backup-path=%s --instance=%s --backup-id=%s --pgdata=%s 2>&1"
_initFmt = "gs_probackup init --backup-path=%s 2>&1"
_deinitFmt = "rm -r %s"
@@ -184,6 +185,22 @@ func (og *openGauss) Stop(pgData string) error {
return nil
}
+// Restore TODO:Dependent environments require integration testing
+func (og *openGauss) Restore(backupPath, instance, backupID, pgData string) error {
+ cmd := fmt.Sprintf(_restoreFmt, backupPath, instance, backupID, pgData)
+ outputs, err := cmds.AsyncExec(og.shell, cmd)
+
+ for output := range outputs {
+ if errors.Is(err, cons.CmdOperateFailed) {
+ return fmt.Errorf("outputs get err=%s,wrap=%w", output.Error, cons.RestoreFailed)
+ }
+ if output.Error != nil {
+ return fmt.Errorf("output.Error[%s] is not nil,wrap=%w", output.Error, cons.RestoreFailed)
+ }
+ }
+ return nil
+}
+
func (og *openGauss) ignore(outputs chan *cmds.Output) {
defer func() {
_ = recover()
diff --git a/pitr/agent/pkg/cmds/cmd.go b/pitr/agent/pkg/cmds/cmd.go
index ebb6b89..2550d02 100644
--- a/pitr/agent/pkg/cmds/cmd.go
+++ b/pitr/agent/pkg/cmds/cmd.go
@@ -72,11 +72,16 @@ func AsyncExec(name string, args ...string) (chan *Output, error) {
}
if err = cmd.Wait(); err != nil {
- output <- &Output{
- Error: err,
+ if _, ok := err.(*exec.ExitError); ok {
+ output <- &Output{
+ Error: cons.CmdOperateFailed,
+ }
+ } else {
+ output <- &Output{
+ Error: fmt.Errorf("cmd.Wait return err=%s,wrap=%w", err, cons.Internal),
+ }
}
}
-
return nil
})(); err != nil {
// only panic err