backups: add an option to change gzip compression level (#128)

This commit is contained in:
PotatoMaaan 2022-09-26 02:47:09 +02:00 committed by GitHub
parent c736c24118
commit c686992e85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -219,6 +219,15 @@ type Backups struct {
// //
// Defaults to 0 (unlimited) // Defaults to 0 (unlimited)
WriteLimit int `default:"0" yaml:"write_limit"` WriteLimit int `default:"0" yaml:"write_limit"`
// CompressionLevel determines how much backups created by wings should be compressed.
//
// "none" -> no compression will be applied
// "best_speed" -> uses gzip level 1 for fast speed
// "best_compression" -> uses gzip level 9 for minimal disk space useage
//
// Defaults to "best_speed" (level 1)
CompressionLevel string `default:"best_speed" yaml:"compression_level"`
} }
type Transfers struct { type Transfers struct {

View File

@ -62,8 +62,21 @@ func (a *Archive) Create(dst string) error {
writer = f writer = f
} }
// The default compression level is BestSpeed
var cl = pgzip.BestSpeed
// Choose which compression level to use based on the compression_level configuration option
switch config.Get().System.Backups.CompressionLevel {
case "none":
cl = pgzip.NoCompression
case "best_speed":
cl = pgzip.BestSpeed
case "best_compression":
cl = pgzip.BestCompression
}
// Create a new gzip writer around the file. // Create a new gzip writer around the file.
gw, _ := pgzip.NewWriterLevel(writer, pgzip.BestSpeed) gw, _ := pgzip.NewWriterLevel(writer, cl)
_ = gw.SetConcurrency(1<<20, 1) _ = gw.SetConcurrency(1<<20, 1)
defer gw.Close() defer gw.Close()