Is it possible to run one logrotate check manually?
LoggingLogrotateLogging Problem Overview
Is it possible to run one iteration of logrotate manually without scheduling it on some interval?
Logging Solutions
Solution 1 - Logging
Yes: logrotate --force $CONFIG_FILE
Solution 2 - Logging
logrotate -d [your_config_file]
invokes debug mode, giving you a verbose description of what would happen, but leaving the log files untouched.
Solution 3 - Logging
If you want to force-run a single specific directory or daemon's log files, you can usually find the configuration in /etc/logrotate.d
, and they will work standalone.
Keep in mind that global configuration specified in /etc/logrotate.conf
will not apply, so if you do this you should ensure you specify all the options you want in the /etc/logrotate.d/[servicename]
config file specifically.
You can try it out with -d
to see what would happen:
logrotate -df /etc/logrotate.d/nginx
Then you can run (using nginx as an example):
logrotate -f /etc/logrotate.d/nginx
And the nginx logs alone will be rotated.
Solution 4 - Logging
You may want to run it in verbose + force mode.
logrotate -vf /etc/logrotate.conf
Solution 5 - Logging
The way to run all of logrotate is:
logrotate -f /etc/logrotate.conf
that will run the primary logrotate file, which includes the other logrotate configurations as well
Solution 6 - Logging
Issue the following command,the way to run specified logrotate:
logrotate -vf /etc/logrotate.d/custom
Options:
-v :show the process
-f :forcing run
custom :user-defined log setting
eg: mongodb-log
# mongodb-log rotate
/data/var/log/mongodb/mongod.log {
daily
dateext
rotate 30
copytruncate
missingok
}
Solution 7 - Logging
Edit /var/lib/logrotate.status (or /var/lib/loglogrotate/logrotate.status) to reset the 'last rotated' date on the log file you want to test.
Then run logrotate YOUR_CONFIG_FILE
.
Or you can use the --force flag, but editing logrotate.status gives you more precision over what does and doesn't get rotated.
Solution 8 - Logging
Created a shell script to solve the problem.
https://antofthy.gitlab.io/software/#logrotate_one
This script will run just the single logrotate sub-configuration file found in "/etc/logrotate.d", but include the global settings from in the global configuration file "/etc/logrotate.conf". You can also use other otpions for testing it...
For example...
logrotate_one -d syslog