mirror of
https://github.com/kopia/kopia.git
synced 2026-01-25 06:48:48 -05:00
* repo: refactored connect code set up cache for server repositories - improved logic to close the cache on last connection - preemptively add all contents with a prefix to the cache - refactored how config is loaded and saved Now cache dir will be stored as relative and resolved to absolute as part of loading and saving the file, in all other places cache dir is expected to be absolute. * server: removed cache directory from the API and UI This won't be easily available and does not seem useful to expose anyway. * cli: enabled cache commands for server repositories * cli: added KOPIA_CACHE_DIRECTORY environment variable This is used on two occassions - when setting up connection (it gets persisted in the config) and later when opening (to override the cache location from config). It makes setting up docker container with mounted cache somewhat easier with one environment variable. * cli: show cache size for the server cache * tls: present more helpful error message that includes SHA256 fingerprint of the TLS server on mismatch * server: return the name of user who attempted to login when authentication fails
75 lines
1.8 KiB
Go
75 lines
1.8 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.Repository) error {
|
|
opts, err := repo.GetCachingOptions(ctx, repositoryConfigFileName())
|
|
if err != nil {
|
|
return errors.Wrap(err, "error getting cache options")
|
|
}
|
|
|
|
if *cacheInfoPathOnly {
|
|
fmt.Println(opts.CacheDirectory)
|
|
return nil
|
|
}
|
|
|
|
entries, err := ioutil.ReadDir(opts.CacheDirectory)
|
|
if err != nil {
|
|
return errors.Wrap(err, "unable to scan cache directory")
|
|
}
|
|
|
|
path2Limit := map[string]int64{
|
|
"contents": opts.MaxCacheSizeBytes,
|
|
"metadata": opts.MaxMetadataCacheSizeBytes,
|
|
"server-contents": opts.MaxCacheSizeBytes,
|
|
}
|
|
|
|
for _, ent := range entries {
|
|
if !ent.IsDir() {
|
|
continue
|
|
}
|
|
|
|
subdir := filepath.Join(opts.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)", opts.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(repositoryReaderAction(runCacheInfoCommand))
|
|
}
|