Skip to content

Commit

Permalink
cmd: send compressed ZFS stream by using -c flag on send (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloyoyoista authored Mar 27, 2020
1 parent 78fea6e commit 725c6b7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func init() {
sendCmd.Flags().BoolVar(&jobInfo.Full, "full", false, "set this flag to take a full backup of the specified volume using the most recent snapshot.")
sendCmd.Flags().BoolVar(&jobInfo.Incremental, "increment", false, "set this flag to do an incremental backup of the most recent snapshot from the most recent snapshot found in the target.")
sendCmd.Flags().DurationVar(&jobInfo.FullIfOlderThan, "fullIfOlderThan", -1*time.Minute, "set this flag to do an incremental backup of the most recent snapshot from the most recent snapshot found in the target unless the it's been greater than the time specified in this flag, then do a full backup.")
sendCmd.Flags().StringVar(&jobInfo.Compressor, "compressor", helpers.InternalCompressor, "specify to use the internal (parallel) gzip implementation or an external binary (e.g. gzip, bzip2, pigz, lzma, xz, etc.) Syntax must be similar to the gzip compression tool) to compress the stream for storage. Please take into consideration time, memory, and CPU usage for any of the compressors used. All manifests utilize the internal compressor.")
sendCmd.Flags().StringVar(&jobInfo.Compressor, "compressor", helpers.InternalCompressor, "specify to use the internal (parallel) gzip implementation or an external binary (e.g. gzip, bzip2, pigz, lzma, xz, etc.) Syntax must be similar to the gzip compression tool) to compress the stream for storage. Please take into consideration time, memory, and CPU usage for any of the compressors used. All manifests utilize the internal compressor. If value is zfs, the zfs stream will be created compressed. See the -c flag on zfs send for more information.")

sendCmd.Flags().IntVar(&jobInfo.MaxFileBuffer, "maxFileBuffer", 5, "the maximum number of files to have active during the upload process. Should be set to at least the number of max parallel uploads. Set to 0 to bypass local storage and upload straight to your destination - this will limit you to a single destination and disable any hash checks for the upload where available.")
sendCmd.Flags().IntVar(&jobInfo.MaxParallelUploads, "maxParallelUploads", 4, "the maximum number of uploads to run in parallel.")
Expand Down
4 changes: 4 additions & 0 deletions helpers/volumeinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const (
BufferSize = 256 * humanize.KiByte // 256KiB
// InternalCompressor is the key used to indicate we want to utilize the internal compressor
InternalCompressor = "internal"
ZfsCompressor = "zfs"
)

// VolumeInfo holds all necessary information for a Volume as part of a backup
Expand Down Expand Up @@ -229,6 +230,7 @@ func (v *VolumeInfo) Extract(ctx context.Context, j *JobInfo, isManifest bool) e
}
v.r = v.rw
case "":
case ZfsCompressor:
default:
v.cmd = exec.CommandContext(ctx, compressor, "-c", "-d")
v.cmd.Stdin = v.r
Expand Down Expand Up @@ -443,6 +445,8 @@ func prepareVolume(ctx context.Context, j *JobInfo, pipe bool, isManifest bool)
})
case "":
printCompressCMD.Do(func() { AppLogger.Infof("Will not be using any compression.") })
case ZfsCompressor:
printCompressCMD.Do(func() { AppLogger.Infof("Will send a ZFS compressed stream") })
default:
extensions = append([]string{compressorName}, extensions...)

Expand Down
5 changes: 5 additions & 0 deletions helpers/zfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ func GetZFSSendCommand(ctx context.Context, j *JobInfo) *exec.Cmd {
zfsArgs = append(zfsArgs, "-p")
}

if j.Compressor == ZfsCompressor {
AppLogger.Infof("Enabling the compression (-c) flag on the send.")
zfsArgs = append(zfsArgs, "-c")
}

if j.IntermediaryIncremental && j.IncrementalSnapshot.Name != "" {
AppLogger.Infof("Enabling an incremental stream with all intermediary snapshots (-I) on the send to snapshot %s", j.IncrementalSnapshot.Name)
zfsArgs = append(zfsArgs, "-I", j.IncrementalSnapshot.Name)
Expand Down

0 comments on commit 725c6b7

Please sign in to comment.