Logrotation Configuration Print

  • 0

Logs should be rotated by the root user. In most cases, logrotate is invoked from a script in the /etc/cron.daily/ directory. First you need to add the script in "/etc/cron.daily/logrotate"

  • #!/bin/sh
  • logrotate /etc/logrotate.conf

Next we have to add the below script in "logrotate.conf"

1 include /etc/logrotate.d

Configuration settings for rotation of specific logs is represented in a block structure as below

rotate 5
compresscmd xz
create 0644 postfix postfix

These can be added in the "logrotate.conf" itself.

The above configuration rotates logs every week, saves the last five rotated logs, compresses all of the old log files with the xz compression tool, and recreates the log files with permissions of 0644 and postfix as the user and group owner. If you specify a rotation number as 0, logs will be removed immediately after they are rotated. The Rotation Intervals can be "weekly", "monthly" and "yearly". So the logs will rotate every weekly or monthly or rearly basis that logrotate runs.

All set go ahead!

Was this answer helpful?

« Back