mirror of
https://github.com/kopia/kopia.git
synced 2026-01-28 08:18:58 -05:00
* cli: make sure we don't run maintenance as part of read-only actions * cli: classified some actions that use *repo.DirectRepository as read-only too
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"sort"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/kopia/kopia/repo"
|
|
)
|
|
|
|
var (
|
|
blockIndexListCommand = indexCommands.Command("list", "List content indexes").Alias("ls").Default()
|
|
blockIndexListSummary = blockIndexListCommand.Flag("summary", "Display index blob summary").Bool()
|
|
blockIndexListIncludeSuperseded = blockIndexListCommand.Flag("superseded", "Include inactive index files superseded by compaction").Bool()
|
|
blockIndexListSort = blockIndexListCommand.Flag("sort", "Index blob sort order").Default("time").Enum("time", "size", "name")
|
|
)
|
|
|
|
func runListBlockIndexesAction(ctx context.Context, rep *repo.DirectRepository) error {
|
|
blks, err := rep.Content.IndexBlobs(ctx, *blockIndexListIncludeSuperseded)
|
|
if err != nil {
|
|
return errors.Wrap(err, "error listing index blobs")
|
|
}
|
|
|
|
switch *blockIndexListSort {
|
|
case "time":
|
|
sort.Slice(blks, func(i, j int) bool {
|
|
return blks[i].Timestamp.Before(blks[j].Timestamp)
|
|
})
|
|
case "size":
|
|
sort.Slice(blks, func(i, j int) bool {
|
|
return blks[i].Length < blks[j].Length
|
|
})
|
|
case "name":
|
|
sort.Slice(blks, func(i, j int) bool {
|
|
return blks[i].BlobID < blks[j].BlobID
|
|
})
|
|
}
|
|
|
|
for _, b := range blks {
|
|
fmt.Printf("%-40v %10v %v %v\n", b.BlobID, b.Length, formatTimestampPrecise(b.Timestamp), b.Superseded)
|
|
}
|
|
|
|
if *blockIndexListSummary {
|
|
fmt.Printf("total %v indexes\n", len(blks))
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func init() {
|
|
blockIndexListCommand.Action(directRepositoryReadAction(runListBlockIndexesAction))
|
|
}
|