Files
kopia/cli/command_cache_info.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

62 lines
1.4 KiB
Go

package cli
import (
"context"
"fmt"
"io/ioutil"
"path/filepath"
"github.com/pkg/errors"
"github.com/kopia/kopia/internal/units"
"github.com/kopia/kopia/repo"
)
var (
cacheInfoCommand = cacheCommands.Command("info", "Displays cache information and statistics").Default()
cacheInfoPathOnly = cacheInfoCommand.Flag("path", "Only display cache path").Bool()
)
func runCacheInfoCommand(ctx context.Context, rep repo.DirectRepository) error {
if *cacheInfoPathOnly {
fmt.Println(rep.CachingOptions().CacheDirectory)
return nil
}
entries, err := ioutil.ReadDir(rep.CachingOptions().CacheDirectory)
if err != nil {
return errors.Wrap(err, "unable to scan cache directory")
}
path2Limit := map[string]int64{
"contents": rep.CachingOptions().MaxCacheSizeBytes,
"metadata": rep.CachingOptions().MaxMetadataCacheSizeBytes,
}
for _, ent := range entries {
if !ent.IsDir() {
continue
}
subdir := filepath.Join(rep.CachingOptions().CacheDirectory, ent.Name())
fileCount, totalFileSize, err := scanCacheDir(subdir)
if err != nil {
return err
}
maybeLimit := ""
if l, ok := path2Limit[ent.Name()]; ok {
maybeLimit = fmt.Sprintf(" (limit %v)", units.BytesStringBase10(l))
}
fmt.Printf("%v: %v files %v%v\n", subdir, fileCount, units.BytesStringBase10(totalFileSize), maybeLimit)
}
return nil
}
func init() {
cacheInfoCommand.Action(directRepositoryReadAction(runCacheInfoCommand))
}