These classnotes are depreciated. As of 2005, I no longer teach the classes. Notes will remain online for legacy purposes

UNIX03/Introduction To Logrotate

Classnotes | UNIX03 | RecentChanges | Preferences

If your log files continue to grow and grow unchecked, you may eventually run out of drive space. Even worse (and more likely) the log files will grow to a point where they are no longer managable for the administrator. So how do we combat this?

Logrotate

Homepage: http://iain.cx/src/logrotate/

One answer (and the most common one at that) is to use Logrotate. Logrotate is designed to ease administration of systems that generate large numbers of log files. It allows automatic rotation, compression, removal, and mailing of log files. Each log file may be handled daily, weekly, monthly, or when it grows too large

Normally, Logrotate runs as a cron job (usually in cron.daily), however it is completely possible to run it manually. It checks its configuration, prepares a variety of scripts, and then proceeds to split and rotate the log files it is set up to manage.

Taking a look in /var/log, you may find files such as these:

 -rw-------    1 root     root   1170950 Oct 10 21:35 maillog
 -rw-------    1 root     root   1867931 Oct  5 04:45 maillog.1
 -rw-------    1 root     root   1319072 Sep 28 04:38 maillog.2
 -rw-------    1 root     root   1574705 Sep 21 04:40 maillog.3
 -rw-------    1 root     root   5000544 Sep 14 04:44 maillog.4
 -rw-------    1 root     root     19104 Oct 10 21:09 messages
 -rw-------    1 root     root      9021 Oct  4 12:49 messages.1
 -rw-------    1 root     root      4460 Sep 27 22:05 messages.2
 -rw-------    1 root     root      7165 Sep 20 13:16 messages.3
 -rw-------    1 root     root     10699 Sep 14 02:16 messages.4

Taking a look just at maillog (which is a log of the mail transactions taking place with this Postfix-based system), we see that the current maillog with all of today's transactions is:

  maillog

Then, we have rotated maillogs separated by several days:

  maillog.1
  maillog.2
  maillog.3
  maillog.4

If you will note, the dates on these files do vary quite a bit. This is because Logrotate can be configured to rotate logs based upon size, date, or a number of other settings.

Logrotate is used by default on many Linux distributions such as Red Hat, Debian, Gentoo, and Mandrake. However, you should be aware that not all distributions presently include it by default (two examples are SUSE and SCO).



Classnotes | UNIX03 | RecentChanges | Preferences
This page is read-only | View other revisions
Last edited October 11, 2003 1:43 am (diff)
Search:
(C) Copyright 2003 Samuel Hart
Creative Commons License
This work is licensed under a Creative Commons License.