Is it possible to run one iteration of logrotate manually without scheduling it on some interval?
-
4The problem with logrotate is that it has one Global configuration file, and it does NOT let you run a single log rotate sub-configuration file while still applying the options set in the global configuration file. That is it does not have a nice way to run just ONE log rotation file check, exactly as it would when run each night from cron. It could do with a 'limit to these log files' option, or better still, 'run the global config, but only include this sub-configuration file'.anthony– anthony2016-11-30 02:27:26 +00:00Commented Nov 30, 2016 at 2:27
8 Answers
Yes: logrotate --force $CONFIG_FILE
9 Comments
--force will rotate file(s) even if they do not meet the specified criteria such as minsize, age, etc.logrotate --force /etc/logrotate.d/ (just directory name)--force will force rotation even if files do not meet criteria (age, size, etc), but please consider that this is the only way to spot real problems that with logrotate -d would not emerge (for example, I had a server running out of space due to logrotate not running for months...and thanks to --force I figured out that there were File exists errors. I manually deleted those files and now rotation correctly works again!logrotate -d [your_config_file] invokes debug mode, giving you a verbose description of what would happen, but leaving the log files untouched.
5 Comments
logrotate --force and works well.logrotate -v <your_config_file> where -v is to verbose the logs on the screen.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.
2 Comments
logrotate -d /etc/logrotate.conf will run through any other included conf files too.You may want to run it in verbose + force mode.
logrotate -vf /etc/logrotate.conf
1 Comment
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
}
1 Comment
Edit /var/lib/logrotate.status (or /var/lib/logrotate/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.
3 Comments
/var/lib/logrotate.status file doesn't exist on Debian Squeeze.logrotate -dv /usr/local/etc/logrotate.conf and look for the line starting with "Reading state from file:"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