ZFS Enable compression for an existing encrypted dataset

Since compression was not used when creating some encrypted datasets, compression can now be enabled only by re-creating these datasets in some way. Namely, (1) simply create new dataset and copy data or (2) create it using zfs receive.

(1) So far I see only one way: create a new encrypted dataset from scratch, but with compression=lz4 property. And after that, just run rsync, which is not ZFS way. But I suspect there are no other options.

(2) Perhaps this can also be done using zfs send/receive? But zfs send requires the --raw flag to be used for an encrypted dataset, which essentially means transmission with the same old degree of compression, even if you enable this property for zfs receive. That is, the following method does not compress data:
Code:
zfs send --raw zpool1/enc@test | zfs receive -uv -o compression=lz4 zpool2/enc
 
If you set encryption during the receive, you can send without raw (encryption keys must be loaded) and then re-encrypt and compress (both set with -o on the recv) the stream into a new dataset.

You won’t be able to do incremental updates with raw in this setup, but if you’re looking to replace the original dataset once the transcoding (decr./compress/encr.) has completed, that shouldn’t be an issue.
 
  • Thanks
Reactions: dnb
For `zfs recv`, make sure to use -x compression if the property is already set in the destination or -o compression=lz4.

https://github.com/pjd/filerewrite was a tool written to rewrite files in place while keeping access/modification times the same. Its readme mentions a few gotchas in case you pursue a route such as that or rsync.
 
Back
Top