Read more

How to rotate log files explicitly

Arne Hartherz
April 04, 2013Software engineer at makandra GmbH

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).

Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

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.

Posted by Arne Hartherz to makandra dev (2013-04-04 13:45)