Linux + how to compress the old log files automatically

compressionlinuxtarzip

Under /var/log/httpd folder, files are created with huge capacity!!!

What solution can I use in order to compress the old files automatically (can logrotate handle this)?

If yes, how to configure the Linux machine in order to compress the old files under this folder?

Second question: What the meaning of those files?

  13:16:50 root@BillGates-Machine:/var/log/httpd # ls -ltr
  -rw-r--r-- 1 root root      7612 Jan 30 05:51 ssl_error_log-20160131
  -rw-r--r-- 1 root root  16170199 Jan 31 03:29 ssl_request_log-20160131
  -rw-r--r-- 1 root root  14677353 Jan 31 03:29 ssl_access_log-20160131
  -rw-r--r-- 1 root root 425621646 Jan 31 03:38 access_log-20160131
  -rw-r--r-- 1 root root     77267 Jan 31 03:38 error_log-20160131
  -rw-r--r-- 1 root root     11233 Feb  7 03:43 ssl_error_log-20160207
  -rw-r--r-- 1 root root  16398688 Feb  7 03:44 ssl_request_log-20160207
  -rw-r--r-- 1 root root  14867381 Feb  7 03:44 ssl_access_log-20160207
  -rw-r--r-- 1 root root 471057664 Feb  7 03:48 access_log-20160207
  -rw-r--r-- 1 root root    101611 Feb  7 03:48 error_log-20160207

Best Answer

logrotate can compress the files it rotates, but it doesn't work well when the log file name the application writes is not static (as is the case here, due to the date suffix in the file name). If you reconfigured the HTTP server (Apache?) so that it doesn't include the date suffix (i.e. it would only write access_log, error_log etc) logrotate could be used. Here's an example solution how to configure it like this.

Here's another related question which also has a solution in case you wish to keep the log file naming scheme. It doesn't use logrotate but a custom script for the job.

The meanings of those files, in short, is

  • access_log: plain HTTP requests that succeed
  • error_log: plain HTTP requests that result in an error
  • ssl_request_log: HTTPS requests that succeed
  • ssl_error_log: HTTPS requests that result in an error

(of course your config might divert from that logic)

Related Question