How to rotate log files explicitly

Posted . Visible to the public.

Usually, the logrotate service takes care of renaming log files each night or so to avoid logs becoming huge. That will rename your.log to your.log.1, the next time to your.log.2.gz, etc. Here is how to make that happen out of band (you should rarely need to do that).

Logrotate won't touch all your logs automagically. There is a config file for each service which you can tell logrotate to use.

So if you need logs to be rotated right now, do this (as root):

logrotate --force PATH_TO_CONFIG_FILE

For example, to rotate all your Apache logs (warning: this usually restarts Apache as well):

logrotate --force /etc/logrotate.d/apache2

Remember that an alternative is to use timestamped logs and logrotate might not touch those for you. If you have them, cast some other kind of magic.

Arne Hartherz
Last edit
Keywords
ubuntu, linux
License
Source code in this card is licensed under the MIT License.
Posted by Arne Hartherz to makandra dev (2013-04-04 11:45)