forked from TrueCloudLab/restic
prune: Add option to repack uncompressed data
This commit is contained in:
parent
5406743102
commit
381bd94c6c
1 changed files with 16 additions and 2 deletions
|
@ -51,6 +51,7 @@ type PruneOptions struct {
|
||||||
MaxRepackBytes uint64
|
MaxRepackBytes uint64
|
||||||
|
|
||||||
RepackCachableOnly bool
|
RepackCachableOnly bool
|
||||||
|
RepackUncompressed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var pruneOptions PruneOptions
|
var pruneOptions PruneOptions
|
||||||
|
@ -68,6 +69,7 @@ func addPruneOptions(c *cobra.Command) {
|
||||||
f.StringVar(&pruneOptions.MaxUnused, "max-unused", "5%", "tolerate given `limit` of unused data (absolute value in bytes with suffixes k/K, m/M, g/G, t/T, a value in % or the word 'unlimited')")
|
f.StringVar(&pruneOptions.MaxUnused, "max-unused", "5%", "tolerate given `limit` of unused data (absolute value in bytes with suffixes k/K, m/M, g/G, t/T, a value in % or the word 'unlimited')")
|
||||||
f.StringVar(&pruneOptions.MaxRepackSize, "max-repack-size", "", "maximum `size` to repack (allowed suffixes: k/K, m/M, g/G, t/T)")
|
f.StringVar(&pruneOptions.MaxRepackSize, "max-repack-size", "", "maximum `size` to repack (allowed suffixes: k/K, m/M, g/G, t/T)")
|
||||||
f.BoolVar(&pruneOptions.RepackCachableOnly, "repack-cacheable-only", false, "only repack packs which are cacheable")
|
f.BoolVar(&pruneOptions.RepackCachableOnly, "repack-cacheable-only", false, "only repack packs which are cacheable")
|
||||||
|
f.BoolVar(&pruneOptions.RepackUncompressed, "repack-uncompressed", false, "repack all uncompressed data")
|
||||||
}
|
}
|
||||||
|
|
||||||
func verifyPruneOptions(opts *PruneOptions) error {
|
func verifyPruneOptions(opts *PruneOptions) error {
|
||||||
|
@ -135,6 +137,10 @@ func runPrune(opts PruneOptions, gopts GlobalOptions) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opts.RepackUncompressed && gopts.Compression == repository.CompressionOff {
|
||||||
|
return errors.Fatal("disabled compression and `--repack-uncompressed` are mutually exclusive")
|
||||||
|
}
|
||||||
|
|
||||||
repo, err := OpenRepository(gopts)
|
repo, err := OpenRepository(gopts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -144,6 +150,10 @@ func runPrune(opts PruneOptions, gopts GlobalOptions) error {
|
||||||
return errors.Fatal("prune requires a backend connection limit of at least two")
|
return errors.Fatal("prune requires a backend connection limit of at least two")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if repo.Config().Version < 2 && opts.RepackUncompressed {
|
||||||
|
return errors.Fatal("compression requires at least repository format version 2")
|
||||||
|
}
|
||||||
|
|
||||||
if opts.UnsafeNoSpaceRecovery != "" {
|
if opts.UnsafeNoSpaceRecovery != "" {
|
||||||
repoID := repo.Config().ID
|
repoID := repo.Config().ID
|
||||||
if opts.UnsafeNoSpaceRecovery != repoID {
|
if opts.UnsafeNoSpaceRecovery != repoID {
|
||||||
|
@ -356,8 +366,12 @@ func prune(opts PruneOptions, gopts GlobalOptions, repo restic.Repository, usedB
|
||||||
stats.packs.partlyUsed++
|
stats.packs.partlyUsed++
|
||||||
}
|
}
|
||||||
|
|
||||||
// repo v2: always repack tree blobs if uncompressed
|
mustCompress := false
|
||||||
mustCompress := repoVersion >= 2 && p.tpe == restic.TreeBlob && p.uncompressed
|
if repoVersion >= 2 {
|
||||||
|
// repo v2: always repack tree blobs if uncompressed
|
||||||
|
// compress data blobs if requested
|
||||||
|
mustCompress = (p.tpe == restic.TreeBlob || opts.RepackUncompressed) && p.uncompressed
|
||||||
|
}
|
||||||
// use a flag that pack must be compressed
|
// use a flag that pack must be compressed
|
||||||
p.uncompressed = mustCompress
|
p.uncompressed = mustCompress
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue