Introduction
- Take a backup of log files periodically as configured/needed, so that at any given point of time we had a backup we could look at
- Compress the backed-up log file, so that system resources are not exploited.
- Delete very old backed-up log files to clear the memory.
Note: By default, when logrotate is installed, logrotate file is copied in /etc/cron.daily folder because of which logrotate is run on a daily basis. Logrotate maintains the log of when logrotate had happen in file /var/lib/logrotate/logrotate.status.
Configuration Files
logrotate.conf
#
see "man logrotate" for details #
rotate log files weekly #
keep 4 weeks worth of backlogs #
create new (empty) log files after rotating old ones #
uncomment this if you want your log files compressed #
RPM packages drop log rotation information into this directory #
no packages own wtmp and btmp -- we'll rotate them here /var/log/btmp
{ #
system-specific logs may be also be configured here. |
Let's analyze each of the configuration mentioned above
weekly |
Files
should be rotated weekly |
dateext |
The
backed-up file name should be suffixed with date of rotation |
compress |
Specifies
that the file should be compressed |
create |
Specifies
that a new log file should be created to log incoming logs. |
rotate
4 |
Specifies
that the amount of backed-up log files should not be more than 4. Delete the
older backed-up log files if the number of backed-up log files is more than
4. |
include /etc/logrotate.d |
logrotate.d
cat /etc/logrotate.d/myapplication /var/log/myapplication/*.log { |
/var/log/myapplication/*.log |
Regex
to identify the log files to be rotated. In this, it will match each file
which ends with .log |
rotate
12 |
The
backed-up file name should be suffixed with date of rotation |
copytruncate |
Specifies
that the file should be compressed |
compress |
Specifies
that a new log file should be created to log incoming logs. |
missingok |
Specifies
that the amount of backed-up log files should not be more than 4. Delete the
older backed-up log files if the number of backed-up log files is more than 4 |
notifempty |
Do
not rotate the file if it is empty |
size
10M |
Log
files are rotated only if the size exceeds 10Mb. |
A single configuration file can have multiple entries as follows:
cat /etc/logrotate.d/myapplication /var/log/myapplication/myapplication.log { /var/log/myapplication/audit.log { |
0 Comments