mirror of
https://github.com/kopia/kopia.git
synced 2026-01-24 22:38:00 -05:00
* cache: improved cache cleanup on exit Ensure we do one full sweep before closing if cache has been modified. Before we would do periodic sweep every minute which would not kick in for very short snapshots, which Kopia does very frequently. This leads to build-up of metadata cache entries (q blobs) that never get cleaned until some long session. * caching: streamlined cache handling - deprecated caching-related flags, now cache is always on or off with no way to disable it per invocation. - reduced default list cache duration from 10min to 30s - moved blob-list cache to separate subdirectory - cleaned up cache info output to include blob-list cache parameters - removed ability to disable cache for per-context (this was only used in 'snapshot verify' codepath) - added ability to partially clear individual caches via CLI
69 lines
1.7 KiB
Go
69 lines
1.7 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))
|
|
}
|
|
|
|
if ent.Name() == "blob-list" {
|
|
maybeLimit = fmt.Sprintf(" (duration %vs)", rep.CachingOptions().MaxListCacheDurationSec)
|
|
}
|
|
|
|
fmt.Printf("%v: %v files %v%v\n", subdir, fileCount, units.BytesStringBase10(totalFileSize), maybeLimit)
|
|
}
|
|
|
|
printStderr("To adjust cache sizes use 'kopia cache set'.\n")
|
|
printStderr("To clear caches use 'kopia cache clear'.\n")
|
|
|
|
return nil
|
|
}
|
|
|
|
func init() {
|
|
cacheInfoCommand.Action(directRepositoryReadAction(runCacheInfoCommand))
|
|
}
|