How To Manage Logfiles with Logrotate: Difference between revisions
From WickyWiki
Created page with "Category:Ubuntu Category:Ubuntu System Category:201904 To prevent your log files from growing without limit the 'logrotate' command can be used to specify what yo..." |
mNo edit summary |
||
| Line 3: | Line 3: | ||
[[Category:201904]] | [[Category:201904]] | ||
To prevent your log files from growing without limit the 'logrotate' command can be used to specify what you want to keep. There are a lot of options and you might want to integrate your log-cleaning into the daily logrotate schedule. This example however is limited to an independent configuration and some basic options. | To prevent your log files from growing without limit the 'logrotate' command can be used to specify what you want to keep. There are a lot of options and you might want to integrate your log-cleaning into the daily logrotate schedule. This example however is limited to an independent configuration and some basic options. <!-- retention rotate logging --> | ||
<!-- retention rotate logging --> | |||
More info here: | More info here: | ||
Revision as of 21:01, 4 March 2019
To prevent your log files from growing without limit the 'logrotate' command can be used to specify what you want to keep. There are a lot of options and you might want to integrate your log-cleaning into the daily logrotate schedule. This example however is limited to an independent configuration and some basic options.
More info here:
Complete info can be found on the man page:
man logrotate
Create logrotate config file:
sudo nano /home/user1/logs/example.conf
/home/user1/logs/*.log {
rotate 4
daily
size 1k
missingok
compress
delaycompress
}
chmod 0444 /home/user1/logs/example.conf
Options explained:
| Option | Meaning |
|---|---|
| rotate 4 | Keep 4 logfiles, older logfiles are deleted |
| daily | Rotate not more than once a day, the state-file is used to check if it was rotated earlier today |
| size 1k | Do not rotate if the logfile size is less than 1k |
| missingok | Do not report an error if the logfile does not exist |
| compress | gz-Compress rotated logfiles |
| delaycompress | Compress after one extra rotation |
Manually logrotate
Option -v (verbose) is added so you can see what is happening.
logrotate -v /home/user1/logs/example.conf --state /home/user1/logs/logrotate-state
Add to daily crontab
The time that was used here is daily at 4:04 am.
nano /etc/crontab
04 04 * * * * /usr/sbin/logrotate /home/user1/logs/example.conf --state /home/user1/logs/logrotate-state