Files
kopia/cli/command_index_list.go
Jarek Kowalski fa7976599c repo: refactored repository interfaces (#780)
- `repo.Repository` is now read-only and only has methods that can be supported over kopia server
- `repo.RepositoryWriter` has read-write methods that can be supported over kopia server
- `repo.DirectRepository` is read-only and contains all methods of `repo.Repository` plus some low-level methods for data inspection
- `repo.DirectRepositoryWriter` contains write methods for `repo.DirectRepository`

- `repo.Reader` removed and merged with `repo.Repository`
- `repo.Writer` became `repo.RepositoryWriter`
- `*repo.DirectRepository` struct became `repo.DirectRepository`
  interface

Getting `{Direct}RepositoryWriter` requires using `NewWriter()` or `NewDirectWriter()` on a read-only repository and multiple simultaneous writers are supported at the same time, each writing to their own indexes and pack blobs.

`repo.Open` returns `repo.Repository` (which is also `repo.RepositoryWriter`).

* content: removed implicit flush on content manager close
* repo: added tests for WriteSession() and implicit flush behavior
* invalidate manifest manager after write session

* cli: disable maintenance in 'kopia server start'
  Server will close the repository before completing.

* repo: unconditionally close RepositoryWriter in {Direct,}WriteSession
* repo: added panic in case somebody tries to create RepositoryWriter after closing repository
  - used atomic to manage SharedManager.closed

* removed stale example
* linter: fixed spurious failures

Co-authored-by: Julio López <julio+gh@kasten.io>
2021-01-20 11:41:47 -08:00

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.IndexBlobReader().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))
}