How to XZ a directory with TAR using maximum compression
tar with maximum compression
With a recent GNU tar on bash or derived shell:
XZ_OPT=-9 tar cJf tarfile.tar.xz directory
tar's lowercase j switch uses bzip, uppercase J switch uses xz.
The XZ_OPT environment variable lets you set xz options that cannot be passed via calling applications such as tar.
This is now maximal.
See man xz for other options you can set (-e/--extreme might give you some additional compression benefit for some datasets).