Categories
Linux

Logrotate & Compression

yum -y install xz

Want to keep lots of logs, yet don’t want them cluttering up your logs directory and want them taking as little space as possible? well lets use a handy utility called logrotate and a compression utility called xz. xz is a lossless data compression program and file format which incorporates the LZMA/LZMA2 compression algorithms. Due to its better compression its great for logrotate so we can compress our existing logs better and end up storing more logs, which helps diagnose issues and facilitates better audit trails.

Install logrotate and xz-utils.

Debian / Ubuntu:

apt-get install logrotate xz-utils

Centos / Redhat:

yum -y install xz

Make a directory for the old logs.

mkdir /var/log/old

now open up

nano /etc/logrotate.conf

Edit at will then at the bottom insert this

compress
compresscmd /usr/bin/xz
uncompresscmd /usr/bin/unxz
compressext .xz
compressoptions -9
olddir /var/log/old

voila ! you are done. feel free to change the -9 to any number between -1 and -9 the lower the number the lower the compression but also lower the cpu/ram usage during said compression.

Leave a Reply

Your email address will not be published. Required fields are marked *