>_ IzzyLab

Hands-on task

This task is step 16 of the course “Logs: analysis and housekeeping”

Weekly rotation of the billing log

medium~7 min

Accounting needs a month of billing history. Create /etc/logrotate.d/billing for /var/log/billing/billing.log: rotate once a week, keep 4 archives, add the date to the archive name instead of a number, and compress the archives.

What you'll practise:
  • logrotate
  • weekly
  • dateext
  • compress
  • scheduled rotation

Topic breakdown

For logs kept "per period", scheduled rotation is more convenient: weekly renames the log into an archive once a week, and rotate limits their number — four weekly archives make a month of history. With dateext the archive gets the rotation date in its name instead of a sequence number: such names don't shift on every rotation and are easier to find and back up. You don't have to wait for the end of the week to check — logrotate -f rotates right away, and -d shows what would be done.

What's checked

  1. the billing log is rotated weekly, 4 archives
  2. archives are dated and compressed
  3. rotation creates a billing.log-YYYYMMDD.gz archive

What it looks like