6

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
  • You could use a filesystem like ZFS or Btrfs and enable automatic filesystem compression. It is a bit too much for such a small problem, but will give you the benefit of transparent compression for all other files too, besides the many benefits of an advanced filesystem! – Teresa e Junior Feb 24 '16 at 13:52
10

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)

4

You can use logrotate.

An example application configuration setting would be the dpkg (Debian package management system), that is stored in /etc/logrotate.d/dpkg. One of the entries in this file would be:

/var/log/dpkg.log {
      monthly
      size 500M
      rotate 12
      compress
      delaycompress
      missingok
      notifempty
      create 644 root root
}

Tutorial here.

1

Add compress operation to cron. Add the following line to root crontab ( sudo crontab -e ):

0 0 * * * tar -czf /var/log/httpd_backup_`date`.tar.gz /var/log/httpd && rm -rf /var/log/httpd/*

This command will create a tar archive with your old logs and remove exist. The job will start at 0 o'clock every day.

  • Why mess with crons when you can use logrotate? – drinxy Mar 25 '16 at 7:39
  • for the very rare scenarios where you can't use logrotate – Paul Richter Dec 16 '18 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.