This commit is contained in:
2026-02-13 21:50:00 +01:00
parent dbfd99f410
commit 1825b50dec
11 changed files with 276 additions and 30 deletions

View File

@@ -5,7 +5,6 @@ package client
import (
"bytes"
"compress/gzip"
"encoding/json"
"fmt"
"io"
@@ -17,6 +16,7 @@ import (
"time"
"github.com/mistifyio/go-zfs"
"github.com/pierrec/lz4/v4"
)
// SnapshotPolicy defines retention settings for automatic snapshots.
@@ -220,17 +220,18 @@ func (c *Client) streamIncrementalToS3(snapshot *zfs.Dataset, base, uploadURL, s
var reader io.Reader = zfsOut
// Apply gzip compression if enabled
// Apply LZ4 compression if enabled
if c.config.Compress {
fmt.Printf(" Compressing with gzip...\n")
fmt.Printf(" Compressing with LZ4...\n")
pr, pw := io.Pipe()
gzWriter := gzip.NewWriter(pw)
lz4Writer := lz4.NewWriter(pw)
lz4Writer.Apply(lz4.BlockSizeOption(lz4.BlockSize(4 * 1024 * 1024))) // 4MB blocks for better performance
go func() {
// Copy zfs output to gzip writer
io.Copy(gzWriter, zfsOut)
// Close gzip writer first to flush footer, then close pipe
gzWriter.Close()
// Copy zfs output to LZ4 writer
io.Copy(lz4Writer, zfsOut)
// Close LZ4 writer first to flush, then close pipe
lz4Writer.Close()
pw.Close()
}()