mirror of
https://github.com/kopia/kopia.git
synced 2026-04-28 18:10:11 -04:00
added pack info output to 'block list'
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/kopia/kopia/repo"
|
||||
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
@@ -12,7 +14,7 @@
|
||||
blockListKind = blockListCommand.Flag("kind", "Block kind").Default("all").Enum("all", "physical", "packed", "nonpacked", "packs")
|
||||
blockListLong = blockListCommand.Flag("long", "Long output").Short('l').Bool()
|
||||
blockListPrefix = blockListCommand.Flag("prefix", "Prefix").String()
|
||||
blockListSort = blockListCommand.Flag("sort", "Sort order").Default("name").Enum("name", "size", "time", "none")
|
||||
blockListSort = blockListCommand.Flag("sort", "Sort order").Default("name").Enum("name", "size", "time", "none", "pack")
|
||||
blockListReverse = blockListCommand.Flag("reverse", "Reverse sort").Short('r').Bool()
|
||||
)
|
||||
|
||||
@@ -34,11 +36,21 @@ func runListBlocksAction(context *kingpin.ParseContext) error {
|
||||
sort.Slice(blocks, func(i, j int) bool { return maybeReverse(blocks[i].Length < blocks[j].Length) })
|
||||
case "time":
|
||||
sort.Slice(blocks, func(i, j int) bool { return maybeReverse(blocks[i].Timestamp.Before(blocks[j].Timestamp)) })
|
||||
case "pack":
|
||||
sort.Slice(blocks, func(i, j int) bool { return maybeReverse(comparePacks(blocks[i], blocks[j])) })
|
||||
}
|
||||
|
||||
for _, b := range blocks {
|
||||
if *blockListLong {
|
||||
fmt.Printf("%-34v %10v %v %v\n", b.BlockID, b.Length, b.Timestamp.Local().Format(timeFormat), b.PackGroup)
|
||||
grp := b.PackGroup
|
||||
if grp == "" {
|
||||
grp = "default"
|
||||
}
|
||||
if b.PackBlockID != "" {
|
||||
fmt.Printf("%-34v %10v %v %v in %v offset %v\n", b.BlockID, b.Length, b.Timestamp.Local().Format(timeFormat), grp, b.PackBlockID, b.PackOffset)
|
||||
} else {
|
||||
fmt.Printf("%-34v %10v %v %v\n", b.BlockID, b.Length, b.Timestamp.Local().Format(timeFormat), grp)
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("%v\n", b.BlockID)
|
||||
}
|
||||
@@ -47,6 +59,14 @@ func runListBlocksAction(context *kingpin.ParseContext) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func comparePacks(a, b repo.BlockInfo) bool {
|
||||
if a, b := a.PackBlockID, b.PackBlockID; a != b {
|
||||
return a < b
|
||||
}
|
||||
|
||||
return a.PackOffset < b.PackOffset
|
||||
}
|
||||
|
||||
func init() {
|
||||
blockListCommand.Action(runListBlocksAction)
|
||||
}
|
||||
|
||||
@@ -34,10 +34,12 @@ type blockLocation struct {
|
||||
|
||||
// BlockInfo is an information about a single block managed by BlockManager.
|
||||
type BlockInfo struct {
|
||||
BlockID string
|
||||
Length int64
|
||||
Timestamp time.Time
|
||||
PackGroup string
|
||||
BlockID string
|
||||
Length int64
|
||||
Timestamp time.Time
|
||||
PackGroup string
|
||||
PackBlockID string
|
||||
PackOffset int64
|
||||
}
|
||||
|
||||
// BlockManager manages storage blocks at a low level with encryption, deduplication and packaging.
|
||||
@@ -504,10 +506,12 @@ func (bm *BlockManager) ListBlocks(prefix string, kind string) []BlockInfo {
|
||||
}
|
||||
|
||||
bm := BlockInfo{
|
||||
BlockID: b,
|
||||
Length: int64(ndx.Items[b].size),
|
||||
Timestamp: ndx.CreateTime,
|
||||
PackGroup: ndx.PackGroup,
|
||||
BlockID: b,
|
||||
Length: int64(ndx.Items[b].size),
|
||||
Timestamp: ndx.CreateTime,
|
||||
PackGroup: ndx.PackGroup,
|
||||
PackBlockID: ndx.PackBlockID,
|
||||
PackOffset: int64(ndx.Items[b].offset),
|
||||
}
|
||||
|
||||
if !blockMatches(bm, ndx) {
|
||||
|
||||
Reference in New Issue
Block a user