LINUX- Logrotate Utility.
Logrotate is a system utility in Linux for managing log files. It allows automatic rotation, compression, removal, and mailing of log files. The logrotate utility is designed to simplify the administration of log files, which are typically generated by system daemons or other system processes. By using logrotate, administrators can ensure that log files do not consume too much disk space and that older log files are archived for future reference.
logrotate is generally available by default in most Linux distributions. It is typically pre-installed and configured on the system, and administrators can use it without having to install it separately. The exact package and configuration file locations may vary depending on the specific Linux distribution you are using, but logrotate is widely supported and widely used across the Linux ecosystem.
logrotate also uses per-application configuration files located in the “/etc/logrotate.d/” directory. These files define specific log rotation policies for individual applications and services running on the system.
Here’s a sample logrotate configuration file that rotates access.log
daily and deletes it after 45 days:
Explanation of the options used in the above configuration:
daily
- This option specifies that the log files should be rotated daily.rotate 45
- This option specifies that logrotate should keep a maximum of 45 rotated log files. When the 46th log file is created, the oldest log file will be deleted.compress
- This option compresses the rotated log files with gzip compression.dateext
- This option adds a date in the format YYYY-MM-DD to the end of the rotated log files.missingok
- This option allows logrotate to continue even if the log file specified in the configuration is missing.notifempty
- This option specifies that logrotate should rotate log files even if they are empty.
The “logrotate.status” file is used by logrotate to track the status of log rotation. It is typically stored in the “/var/lib/logrotate/” directory, and contains information about which log files have been rotated, when they were last rotated, and any errors or issues that occurred during the rotation process.
The “logrotate.status” file is used by logrotate to ensure that log files are rotated only once per rotation interval, even if logrotate is run multiple times. It also helps logrotate to maintain continuity in the log file history, by tracking which log files have been rotated and when.