Use LZ4 with tar for compress multiple directories

lz4 is an extremely fast lossless compression algorithm, based on byte-aligned LZ77 family of compression scheme. lz4 offers compression speeds of 400 MB/s per core, linearly scalable with multi-core CPUs. It features an extremely fast decoder, with speed in multiple GB/s per core, typically reaching RAM speed limit on multi-core systems. The native file format is the .lz4 format. But lz4 accept input with files only if want to compress directory we need to tar them into tar files before compress it.

First install lz4

apt install liblz4-tool

Then compress it

tar cf - dir1 dir2 dir3 dirX | lz4 -v > file_name.tar.lz4
tar cf - dir_pattern* | lz4 -v > file_name.tar.lz4

Finally decompress it

lz4 -d -v file_name.tar.lz4 | tar xf - -C /target/directory

For backup disk image

sudo bash -c "pv /dev/{disk} | lz4 > backup.img.lz4"

For restore disk image

sudo lz4 -d -c -v backup.img.lz4 > /dev/{disk}