>_ IzzyLab

Hands-on task

This task is step 9 of the course “Running a server”

Daily Rotation with a Date

medium~7 min

Configure logrotate for /var/log/app/app.log: rotate daily, keep 7 copies, add a date to the filename (dateext), and compress. The config is /etc/logrotate.d/app.

What you'll practise:
  • logrotate
  • log rotation
  • dateext
  • compression
  • config in /etc/logrotate.d

Topic breakdown

Logs grow endlessly and sooner or later eat up the disk; logrotate periodically renames the current log to an archive, starts a new one, and deletes the oldest copies. Rules for a specific log are placed as a separate file in /etc/logrotate.d/: the path to the log, followed by a block of options in curly braces, one per line — the rotation frequency, the limit of kept copies (rotate + a number), a date suffix instead of a number (dateext), and archive compression (compress). To check the config without waiting for the day, a forced run logrotate -f helps.

What's checked

  1. app.log rotates daily, 7 copies
  2. a date is added to the copy's name
  3. old copies are compressed

What it looks like