Skip to content

Commit

Permalink
br: support ebs offline test by openebs
Browse files Browse the repository at this point in the history
Signed-off-by: BornChanger <[email protected]>
  • Loading branch information
BornChanger committed Apr 25, 2023
1 parent f64cc69 commit f74ae14
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
35 changes: 35 additions & 0 deletions br/pkg/task/backup_ebs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import (
"encoding/json"
"fmt"
"io"
"os"
"os/exec"
"sort"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -220,6 +223,38 @@ func RunBackupEBS(c context.Context, g glue.Glue, cfg *BackupConfig) error {
}
log.Info("async snapshots finished.")
} else {
if _, err := os.Stat("/usr/local/bin/create-snapshot.sh"); err == nil {
log.Info("start to create snapshots")
if err := os.WriteFile("backupmeta.json", []byte(backupInfo.String()), 0644); err != nil {
return errors.Trace(err)
}
cmd := exec.Command("create-snapshot.sh", cfg.VolumeFile)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
log.Warn("failed to create snapshots", zap.Error(err))
return errors.Trace(err)
}
// Script should write snapshot id to /snapshot-id.txt.
// Each line contains: <volume-id> <snapshot-id>
data, err := os.ReadFile("snapshot-ids.txt")
if err != nil {
return errors.Trace(err)
}
log.Info("create snapshots finished", zap.String("snapshot-ids", string(data)))
for _, line := range strings.Split(string(data), "\n") {
if strings.TrimSpace(line) == "" {
continue
}
fields := strings.Split(line, " ")
if len(fields) != 2 {
log.Warn("invalid snapshot id line", zap.String("line", line))
continue
}
volumeID, snapID := strings.TrimSpace(fields[0]), strings.TrimSpace(fields[1])
snapIDMap[volumeID] = snapID
}
}
for i := 0; i < int(storeCount); i++ {
progress.IncBy(100)
totalSize = 1024
Expand Down
35 changes: 35 additions & 0 deletions br/pkg/task/restore_ebs_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"crypto/tls"
"encoding/json"
"os"
"os/exec"
"strings"
"time"

Expand Down Expand Up @@ -199,6 +200,40 @@ func (h *restoreEBSMetaHelper) doRestore(ctx context.Context, progress glue.Prog
}

if h.cfg.SkipAWS {
if _, err := os.Stat("/usr/local/bin/install-snapshot.sh"); err == nil {
log.Info("start to install snapshots")
if err := os.WriteFile("backupmeta.json", []byte(h.metaInfo.String()), 0644); err != nil {
return 0, errors.Trace(err)
}
cmd := exec.Command("install-snapshot.sh")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
log.Warn("failed to install snapshots", zap.Error(err))
return 0, errors.Trace(err)
}
// Script should write the restore volume ids to /volume-ids.txt.
// Each line contains: <volume-id> <restore-volume-id>
data, err := os.ReadFile("volume-ids.txt")
if err != nil {
return 0, errors.Trace(err)
}
log.Info("install snapshots finished", zap.String("volume-ids", string(data)))
volumeIDMap := make(map[string]string)
for _, line := range strings.Split(string(data), "\n") {
if strings.TrimSpace(line) == "" {
continue
}
fields := strings.Split(line, " ")
if len(fields) != 2 {
log.Warn("invalid volume id line", zap.String("line", line))
continue
}
volumeID, restoreVolumeID := strings.TrimSpace(fields[0]), strings.TrimSpace(fields[1])
volumeIDMap[volumeID] = restoreVolumeID
}
h.metaInfo.SetRestoreVolumeIDs(volumeIDMap)
}
for i := 0; i < int(h.metaInfo.GetStoreCount()); i++ {
progress.Inc()
log.Info("mock: create volume from snapshot finished.", zap.Int("index", i))
Expand Down

0 comments on commit f74ae14

Please sign in to comment.