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/16 08:40:03 UTC
[shardingsphere-on-cloud] branch main updated: feat:add show cmd and update the test case (#205)
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 ba38f4b feat:add show cmd and update the test case (#205)
ba38f4b is described below
commit ba38f4b363067139a8957829b15ae3e9d8a4fc6d
Author: lltgo <ll...@outlook.com>
AuthorDate: Thu Feb 16 16:39:58 2023 +0800
feat:add show cmd and update the test case (#205)
* feat:add show func and update test case
* chore:update license
---
pitr/agent/internal/cons/error.go | 1 +
pitr/agent/internal/pkg/model/backup.go | 54 +++++++++++++++++++++++++++++++
pitr/agent/internal/pkg/opengauss.go | 32 +++++++++++++++++-
pitr/agent/internal/pkg/opengauss_test.go | 36 +++++++++++++++++----
4 files changed, 116 insertions(+), 7 deletions(-)
diff --git a/pitr/agent/internal/cons/error.go b/pitr/agent/internal/cons/error.go
index b7033f1..1bfe795 100644
--- a/pitr/agent/internal/cons/error.go
+++ b/pitr/agent/internal/cons/error.go
@@ -24,4 +24,5 @@ import (
var (
Internal = xerror.New(10000, "Internal error.")
InvalidHttpHeader = xerror.New(10001, "Invalid http header.")
+ DataNotFound = xerror.New(10002, "Data not found.")
)
diff --git a/pitr/agent/internal/pkg/model/backup.go b/pitr/agent/internal/pkg/model/backup.go
new file mode 100644
index 0000000..017a64d
--- /dev/null
+++ b/pitr/agent/internal/pkg/model/backup.go
@@ -0,0 +1,54 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+ */
+
+package model
+
+type (
+ Backup struct {
+ ID string `json:"id"`
+ BackupMode string `json:"backup-mode"`
+ Wal string `json:"wal"`
+ CompressAlg string `json:"compress-alg"`
+ CompressLevel int `json:"compress-level"`
+ FromReplica string `json:"from-replica"`
+ BlockSize int `json:"block-size"`
+ XlogBlockSize int `json:"xlog-block-size"`
+ ChecksumVersion int `json:"checksum-version"`
+ ProgramVersion string `json:"program-version"`
+ ServerVersion string `json:"server-version"`
+ CurrentTli int `json:"current-tli"`
+ ParentTli int `json:"parent-tli"`
+ StartLsn string `json:"start-lsn"`
+ StopLsn string `json:"stop-lsn"`
+ StartTime string `json:"start-time"`
+ EndTime string `json:"end-time"`
+ RecoveryXid int `json:"recovery-xid"`
+ RecoveryTime string `json:"recovery-time"`
+ RecoveryName string `json:"recovery-name"`
+ DataBytes int `json:"data-bytes"`
+ WalBytes int `json:"wal-bytes"`
+ UncompressedBytes int `json:"uncompressed-bytes"`
+ PgdataBytes int `json:"pgdata-bytes"`
+ Status string `json:"status"`
+ ContentCrc int64 `json:"content-crc"`
+ }
+
+ BackupList struct {
+ Instance string `json:"instance"`
+ List []Backup `json:"backups"`
+ }
+)
diff --git a/pitr/agent/internal/pkg/opengauss.go b/pitr/agent/internal/pkg/opengauss.go
index 9f62dd7..a837846 100644
--- a/pitr/agent/internal/pkg/opengauss.go
+++ b/pitr/agent/internal/pkg/opengauss.go
@@ -18,8 +18,12 @@
package pkg
import (
+ "encoding/json"
"fmt"
+ "github.com/apache/shardingsphere-on-cloud/pitr/agent/internal/cons"
+ "github.com/apache/shardingsphere-on-cloud/pitr/agent/internal/pkg/model"
+
"github.com/dlclark/regexp2"
"github.com/apache/shardingsphere-on-cloud/pitr/agent/pkg/cmds"
@@ -31,11 +35,12 @@ type openGauss struct {
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 "
)
func (og *openGauss) AsyncBackup(backupPath, instanceName, backupMode, pgData string) (string, error) {
cmd := fmt.Sprintf(_backupFmt, backupPath, instanceName, backupMode, pgData)
- outputs, err := cmds.AsyncExec(og.shell, fmt.Sprintf(_backupFmt, backupPath, instanceName, backupMode, pgData))
+ outputs, err := cmds.AsyncExec(og.shell, cmd)
if err != nil {
return "", fmt.Errorf("cmds.AsyncExec[shell=%s,cmd=%s] return err=%w", og.shell, cmd, err)
}
@@ -57,6 +62,31 @@ func (og *openGauss) AsyncBackup(backupPath, instanceName, backupMode, pgData st
return "", fmt.Errorf("unknow err")
}
+func (og *openGauss) ShowBackupDetail(backupPath, instanceName, backupID string) (*model.Backup, error) {
+ cmd := fmt.Sprintf(_showFmt, instanceName, backupPath, backupID)
+ 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[0], 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 79f0299..d93dcec 100644
--- a/pitr/agent/internal/pkg/opengauss_test.go
+++ b/pitr/agent/internal/pkg/opengauss_test.go
@@ -27,22 +27,46 @@ import (
)
var _ = Describe("OpenGauss,requires opengauss environment", func() {
- Context("AsyncBackup", func() {
- It("One backup", func() {
+ Context("AsyncBackup & ShowBackupDetail", func() {
+ It("One backup and show", func() {
og := &openGauss{
shell: "/bin/sh",
}
+
+ var (
+ data = "/home/omm/data"
+ instance = "ins-default-0"
+ )
+
backupID, err := og.AsyncBackup(
- "/home/omm/data",
- "ins-default-0",
+ data,
+ instance,
"full",
"/data/opengauss/3.1.1/data/single_node/",
)
-
+
Expect(err).To(BeNil())
Expect(backupID).NotTo(BeEmpty())
fmt.Println(fmt.Sprintf("BackupID:%s", backupID))
- time.Sleep(time.Second * 10)
+
+ // timeout 60s
+ for i := 0; i < 60; i++ {
+ backup, err := og.ShowBackupDetail(
+ data,
+ instance,
+ backupID,
+ )
+
+ Expect(err).To(BeNil())
+ Expect(backup).NotTo(BeNil())
+ Expect(backup.ID).To(Equal(backupID))
+ if backup.Status == "OK" {
+ goto End
+ }
+ time.Sleep(time.Second)
+ }
+ Fail("Timeout[60s]")
+ End:
})
})
})