forked from TrueCloudLab/restic
snapshots: Print snapshot size stored in snapshots
This commit is contained in:
parent
38f91d3b5e
commit
b6520038fd
1 changed files with 14 additions and 0 deletions
|
@ -9,6 +9,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/restic/restic/internal/restic"
|
||||
"github.com/restic/restic/internal/ui"
|
||||
"github.com/restic/restic/internal/ui/table"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
@ -163,6 +164,11 @@ func PrintSnapshots(stdout io.Writer, list restic.Snapshots, reasons []restic.Ke
|
|||
keepReasons[*id] = reasons[i]
|
||||
}
|
||||
}
|
||||
// check if any snapshot contains a summary
|
||||
hasSize := false
|
||||
for _, sn := range list {
|
||||
hasSize = hasSize || (sn.Summary != nil)
|
||||
}
|
||||
|
||||
// always sort the snapshots so that the newer ones are listed last
|
||||
sort.SliceStable(list, func(i, j int) bool {
|
||||
|
@ -198,6 +204,9 @@ func PrintSnapshots(stdout io.Writer, list restic.Snapshots, reasons []restic.Ke
|
|||
tab.AddColumn("Reasons", `{{ join .Reasons "\n" }}`)
|
||||
}
|
||||
tab.AddColumn("Paths", `{{ join .Paths "\n" }}`)
|
||||
if hasSize {
|
||||
tab.AddColumn("Size", `{{ .Size }}`)
|
||||
}
|
||||
}
|
||||
|
||||
type snapshot struct {
|
||||
|
@ -207,6 +216,7 @@ func PrintSnapshots(stdout io.Writer, list restic.Snapshots, reasons []restic.Ke
|
|||
Tags []string
|
||||
Reasons []string
|
||||
Paths []string
|
||||
Size string
|
||||
}
|
||||
|
||||
var multiline bool
|
||||
|
@ -228,6 +238,10 @@ func PrintSnapshots(stdout io.Writer, list restic.Snapshots, reasons []restic.Ke
|
|||
multiline = true
|
||||
}
|
||||
|
||||
if sn.Summary != nil {
|
||||
data.Size = ui.FormatBytes(sn.Summary.TotalBytesProcessed)
|
||||
}
|
||||
|
||||
tab.AddRow(data)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue