Junior — Middle
Can you explain what is meant by the logrotate tool and how it works?
sobes.tech AI
Answer from AI
Logrotate is a utility in Unix-like systems that automates the management of log files. It helps prevent disk overflow due to overly large logs by periodically archiving, compressing, deleting, or renaming old log files.
Working principle:
- Logrotate is run on a schedule (usually via cron).
- It reads configuration files that specify log paths and rotation rules (e.g., file size, frequency).
- If conditions are met (e.g., log reaches a certain size or a day has passed), logrotate renames the current log (for example, adding a date or number suffix), creates a new empty log, and compresses old logs if necessary.
Example configuration for Apache logs:
/var/log/apache2/*.log {
daily
rotate 7
compress
missingok
notifempty
create 640 root adm
}
Here, logs are rotated daily, 7 archives are kept, old logs are compressed, and new files are created with specified permissions.