Rotation and archiving of logs (logrotate)
Prevent log files from saturating the disk by configuring their automatic rotation.
What this tutorial does
The tutorial "Rotation and archiving of logs (logrotate)" helps you achieve this goal:
Prevent log files from saturating the disk by configuring their automatic rotation.
Debian/Ubuntu
- logrotate is installed by default. Check: logrotate --version
- --- Create a rule for a custom application ---
- Create /etc/logrotate.d/my-app:
- /var/log/mon-app/*.log {
- daily
- missingok
- rotate 14
- compress
- delaycompress
- notifempty
- create 0640 www-data adm
- sharedscripts
- postrotate
-
systemctl reload mon-app > /dev/null 2>&1 || true - endscript
- }
- --- Test the configuration ---
- logrotate --debug /etc/logrotate.d/mon-app
- --- Force manual rotation ---
- logrotate --force /etc/logrotate.d/mon-app
- --- Check rotation history ---
- cat /var/lib/logrotate/status