How to migrate a ZFS filesystem to use compression?

Solution 1:

Copy the data.

That is all.

There's a bunch of missing output in your examples, but it doesn't matter. The only thing you need to do to move data into a compressed filesystem is to rewrite the data either by copying it, moving it or populating a new filesystem.

Avoid the problem in future situations by enabling compression at the pool level so that it's inherited by new filesystems. Also, use lz4 compression flag. It's generally better.

Solution 2:

Even though dump.txt is highly compressible it turns out, that zfs won't compress it for some reason.

Redoing my experiments again with other data, it turns out that send/receive will compress the data. Here I have set the compression on the zpool, so all file systems would inherit this. I also used Linux here, but that shouldn't matter.

# dd if=/dev/zero of=/mnt/dat0/zpool1 bs=1M count=1000
# dd if=/dev/zero of=/mnt/dat0/zpool2 bs=1M count=1000
# service zfs-fuse restart
# zpool create zpool1 /mnt/dat0/zpool1 
# zpool create zpool2 /mnt/dat0/zpool2
# zfs set compression=on zpool1
# zfs create zpool1/fs1
# zfs create zpool2/fs2
# cp -r /etc/ /var/log /zpool2/fs2/
# zfs snapshot zpool2/fs2@snap
# zfs send zpool2/fs2@snap | zfs receive zpool1/fs2
# zfs get compressratio zpool1/fs2
NAME        PROPERTY       VALUE  SOURCE
zpool1/fs2  compressratio  4.75x  -