Use XZ with logrotate

Aug. 16, 2013

Hello.

XZ is a compression format which I like to use, mostly for its good results when compressing text files. And I was seeking to use it with logrotate.

And it’s done now with these 3 lines added in /etc/logrotate.conf :

compresscmd /usr/bin/xz compressext .xz uncompresscmd /usr/bin/unxz

The default compress argument is “-9”, which is working with xz, so no need to edit.

In my servers, logrotate only rotates logfiles in /var/log, so this find command uncompressed GZIP files and compressed them in XZ format :

find /var/log -name “*.gz” | while read filename; do gunzip $filename && xz -vz9 ${filename%.gz}; done

On Debian, the XZ format tools are available in the xz-utils package.

That’s all folks !