mirror of
https://github.com/restic/restic.git
synced 2025-10-26 09:39:27 +00:00
prune: make small pack size configureable for prune all changes together
cmd_prune.go: added option `--repack-smaller-than` prune.go: added field `SmallPackBytes` to `PruneOptions`, including checking and processing prune_test.go: added test `TestPruneSmall` doc/060_forget.rst: added description of enhancement changelog/unreleased/issue-5109: description of enhancement
This commit is contained in:
@@ -67,6 +67,9 @@ type PruneOptions struct {
|
||||
RepackCacheableOnly bool
|
||||
RepackSmall bool
|
||||
RepackUncompressed bool
|
||||
|
||||
SmallPackSize string
|
||||
SmallPackBytes uint64
|
||||
}
|
||||
|
||||
func (opts *PruneOptions) AddFlags(f *pflag.FlagSet) {
|
||||
@@ -81,6 +84,7 @@ func (opts *PruneOptions) AddLimitedFlags(f *pflag.FlagSet) {
|
||||
f.BoolVar(&opts.RepackCacheableOnly, "repack-cacheable-only", false, "only repack packs which are cacheable")
|
||||
f.BoolVar(&opts.RepackSmall, "repack-small", false, "repack pack files below 80% of target pack size")
|
||||
f.BoolVar(&opts.RepackUncompressed, "repack-uncompressed", false, "repack all uncompressed data")
|
||||
f.StringVar(&opts.SmallPackSize, "repack-smaller-than", "", "pack `below-limit` packfiles (allowed suffixes: k/K, m/M)")
|
||||
}
|
||||
|
||||
func verifyPruneOptions(opts *PruneOptions) error {
|
||||
@@ -139,6 +143,20 @@ func verifyPruneOptions(opts *PruneOptions) error {
|
||||
}
|
||||
}
|
||||
|
||||
if !opts.RepackSmall && opts.SmallPackSize != "" {
|
||||
return errors.Fatal("option --repack-small and --repack-smaller-than: must be specified together")
|
||||
}
|
||||
|
||||
opts.SmallPackBytes = uint64(0)
|
||||
if opts.SmallPackSize != "" {
|
||||
size, err := ui.ParseBytes(opts.SmallPackSize)
|
||||
if err != nil {
|
||||
return errors.Fatalf("invalid number of bytes %q for --repack-smaller-than: %v", opts.SmallPackSize, err)
|
||||
}
|
||||
opts.SmallPackBytes = uint64(size)
|
||||
opts.RepackSmall = true
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user