Execute Logrotate Command Manually


One day while perusing around one of my Debian Linux servers I noticed that the disk was extremely full. It isn’t a server I access all the time so the disk space being filled up had gone unnoticed. After taking a look at what could be using up all the disk space, I realised that my log files had grown to be absolutely massive with some log files being a few GB’s in size.

logrotate.d Wasn’t Running

The cause of the issue was that logrotate had not been running for quite some time. I fixed logrotate but I couldn’t afford to wait for the logrotate to automatically run on it’s next schedule. I began to panic and needed to quickly rotate the logs to regain precious space before the server and websites came crashing down.

Execute Logrotate Command Manually

Since most of my disk space was consumed by apache, I decided to execute logrotate command manually in linux and pass it the config of the logrotate apache . To do so, I used the following command:

logrotate -vf /etc/logrotate.d/apache2.conf

The flags ‘-vf’ passed to the command are as follows:

  • -v verbose shows more information. useful to try detect any errors there may be with logrotate
  • -f force the rotation to occur even if it is not necessarily needed

And /etc/logrotate.d/apache2.conf is the location of my config file of for the apache2 logrotate. The content of my config file are as follows

/var/log/apache2/*_log {
	rotate 52
	create 640 root adm
		if [ -f /var/run/apache2.pid ]; then
			/etc/init.d/apache2 restart > /dev/null

Once I ran logrotate in linux manually, all my apache2 log files got rotated, compressed with gzip and recycled leaving me with heaps more free disk space.