Linux Labs

Packages, services, and logs / Stage 12 of 13

Log rotation and retention

Not running Starting usually ~20 s
Leave the lesson

Step 1 of 9 · on a machine · 5 min

The rule is there, the log is unchanged

What you will learn

  • Read a logrotate rule and tell a rotation plan from a performed rotation.
  • Limit the space the systemd journal takes and free it.
  • Rotate a log so that the program keeps writing to the new one.

The application log /var/log/lab-rotate/app.log has grown, and a rotation rule was written for it. A colleague ran logrotate with the --debug option "to see the details" and is sure the rotation happened. Repeat after them and compare the directory before and after.

Exercise · look

Rotation with --debug

You are in /srv/rotate-lab. Look at the log directory, run logrotate the way your colleague did, and look at the directory again.

First, predict

logrotate will print log needs rotating and renaming /var/log/lab-rotate/app.log to /var/log/lab-rotate/app.log.1. What will the directory hold after the command?

Now start the exercise, run the command and compare your prediction with the output.

Sign in and start The machine is available after signing in
Check yourself 1 question

Why did logrotate describe renaming app.log, while the files in the directory did not change?

  • logrotate printed log needs rotating: 2048 bytes is over the size 1k threshold.

  • The timer runs logrotate with the system rules in /etc/logrotate.d. The rule in /srv/rotate-lab is not among them.

  • The command ran through sudo, and the output has no permission errors. On its first line logrotate itself says it does nothing in debug mode.

--debug only showed the rotation plan, as logrotate warned on its first line.

Ubuntu 24.04
Loading…