Logrotate snippets
Code snippets for Logrotate.
Manually rotate log files
To rotate log files manually, use the
-f
(force) option. This forces the rotation of logs
$ sudo logrotate -f /etc/logrotate.d/my_filename
Note: Change "my_filename" accordingly.
Force rotate log files
To force rotate a log file, use the
-f
(force) option. This parameter forces the rotation of logs, even when not necessary. The force option command may be necessary when new entries are added in your configuration file.
$ sudo logrotate -f /etc/logrotate.d/my_filename
Note: Change "my_filename" accordingly.
Remove log files after a specified time
To remove log files a specified time (such as 30 days), use the the maxageparameter in the configuration directive:
For example, if you're editing the Nginx log configuration file, use
maxage 30
(where
30
is
30 days
):
var/log/nginx/*.log{
...
maxage 30
rotate 14
daily
dateext
dateformat -%d%m%Y
}
For 24 hours, use
maxage 1
; for 6 months, use
maxage 182
; and so on.
Move log files to a different folder
To move log files to a different folder, use
olddir directory
parameter.
/var/log/nginx/*.log {
...
olddir /var/log/nginx/my_new_folder
...
}
The above code snippet will move the
.log
files from
/var/log/nginx
directory to the
/var/log/nginx/my_new_folder
.
Run in debug mode
To run Logrotate in debug mode, use the
-d
(debug) option:
$ sudo logrotate /etc/logrotate.conf --debug