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 money motivation

Opscomplete powered by makandra brand

Save money by migrating from AWS to our fully managed hosting in Germany.

  • Trusted by over 100 customers
  • Ready to use with Ruby, Node.js, PHP
  • Proactive management by operations experts
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)