Skip to content

PBM-1544 Add new column showing the backup status update #1144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions cmd/pbm/list.go
Original file line number Diff line number Diff line change
@@ -314,14 +314,15 @@ func getSnapshotList(
}

s = append(s, snapshotStat{
Name: b.Name,
Namespaces: b.Namespaces,
Status: b.Status,
RestoreTS: int64(b.LastWriteTS.T),
PBMVersion: b.PBMVersion,
Type: b.Type,
SrcBackup: b.SrcBackup,
StoreName: b.Store.Name,
Name: b.Name,
Namespaces: b.Namespaces,
Status: b.Status,
PrintStatus: b.Status.PrintStatus(),
RestoreTS: int64(b.LastWriteTS.T),
PBMVersion: b.PBMVersion,
Type: b.Type,
SrcBackup: b.SrcBackup,
StoreName: b.Store.Name,
})
}

23 changes: 12 additions & 11 deletions cmd/pbm/main.go
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@
follow bool
}

type cliResult interface {

Check failure on line 58 in cmd/pbm/main.go

GitHub Actions / runner / golangci-lint

type `cliResult` is unused (unused)
HasError() bool
}

@@ -1099,17 +1099,18 @@
}

type snapshotStat struct {
Name string `json:"name"`
Namespaces []string `json:"nss,omitempty"`
Size int64 `json:"size,omitempty"`
Status defs.Status `json:"status"`
Err error `json:"-"`
ErrString string `json:"error,omitempty"`
RestoreTS int64 `json:"restoreTo"`
PBMVersion string `json:"pbmVersion"`
Type defs.BackupType `json:"type"`
SrcBackup string `json:"src"`
StoreName string `json:"storage,omitempty"`
Name string `json:"name"`
Namespaces []string `json:"nss,omitempty"`
Size int64 `json:"size,omitempty"`
Status defs.Status `json:"status"`
PrintStatus defs.PrintStatus `json:"printStatus"`
Err error `json:"-"`
ErrString string `json:"error,omitempty"`
RestoreTS int64 `json:"restoreTo"`
PBMVersion string `json:"pbmVersion"`
Type defs.BackupType `json:"type"`
SrcBackup string `json:"src"`
StoreName string `json:"storage,omitempty"`
}

type pitrRange struct {
18 changes: 4 additions & 14 deletions cmd/pbm/status.go
Original file line number Diff line number Diff line change
@@ -470,35 +470,22 @@ func (s storageStat) String() string {
return a.RestoreTS > b.RestoreTS
})

const (
statusSuccess = "success"
statusFailed = "failed"
statusOngoing = "ongoing"
)

var printStatus string

for i := range s.Snapshot {
ss := &s.Snapshot[i]
var status string
switch ss.Status {
case defs.StatusDone:
status = fmt.Sprintf("[restore_to_time: %s]", fmtTS(ss.RestoreTS))
printStatus = statusSuccess
case defs.StatusCancelled:
status = fmt.Sprintf("[!canceled: %s]", fmtTS(ss.RestoreTS))
printStatus = statusFailed
case defs.StatusError:
if errors.Is(ss.Err, errIncompatible) {
status = fmt.Sprintf("[incompatible: %s] [%s]", ss.Err.Error(), fmtTS(ss.RestoreTS))
printStatus = statusSuccess
} else {
status = fmt.Sprintf("[ERROR: %s] [%s]", ss.Err.Error(), fmtTS(ss.RestoreTS))
printStatus = statusFailed
}
default:
status = fmt.Sprintf("[running: %s / %s]", ss.Status, fmtTS(ss.RestoreTS))
printStatus = statusOngoing
}

t := string(ss.Type)
@@ -510,7 +497,7 @@ func (s storageStat) String() string {
if ss.StoreName != "" {
t += ", *"
}
ret += fmt.Sprintf(" %s %s <%s> %s %s\n", ss.Name, storage.PrettySize(ss.Size), t, printStatus, status)
ret += fmt.Sprintf(" %s %s <%s> %s %s\n", ss.Name, storage.PrettySize(ss.Size), t, ss.PrintStatus, status)
}

if len(s.PITR.Ranges) == 0 {
@@ -612,6 +599,7 @@ func getStorageStat(
snpsht.Err = err
snpsht.ErrString = err.Error()
}
snpsht.PrintStatus = snpsht.Status.PrintStatus(snpsht.Err)

switch bcp.Status {
case defs.StatusError:
@@ -629,6 +617,7 @@ func getStorageStat(
snpsht.Err = errors.New(errStr)
snpsht.ErrString = errStr
snpsht.Status = defs.StatusError
snpsht.PrintStatus = defs.StatusError.PrintStatus()
}
}

@@ -638,6 +627,7 @@ func getStorageStat(
snpsht.Err = err
snpsht.ErrString = err.Error()
snpsht.Status = defs.StatusError
snpsht.PrintStatus = defs.StatusError.PrintStatus()
}

s.Snapshot = append(s.Snapshot, snpsht)
36 changes: 36 additions & 0 deletions pbm/defs/defs.go
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import (
"time"

"github.com/percona/percona-backup-mongodb/pbm/compress"
"github.com/percona/percona-backup-mongodb/pbm/errors"
)

const (
@@ -125,6 +126,41 @@ func (s Status) IsRunning() bool {
return true
}

type PrintStatus string

const (
statusSuccess PrintStatus = "success"
statusFailed PrintStatus = "failed"
statusOngoing PrintStatus = "ongoing"
)

var ErrIncompatible = errors.New("incompatible")

func (s Status) PrintStatus(errs ...error) PrintStatus {
var err error
if len(errs) > 0 {
err = errs[0]
}

switch s {
case StatusDone:
return statusSuccess

case StatusCancelled:
return statusFailed

case StatusError:
// "incompatible" is treated as success
if err != nil && errors.Is(err, ErrIncompatible) {
return statusSuccess
}
return statusFailed

default:
return statusOngoing
}
}

type Operation string

const (
Loading
Oops, something went wrong.