added pack info output to 'block list'

This commit is contained in:
Jarek Kowalski
2017-10-08 20:49:25 -07:00
parent ce5d9b2247
commit a6a37b709a
2 changed files with 34 additions and 10 deletions

View File

@@ -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)
}

View File

@@ -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) {