• Skip to main content
  • Home
  • About Me
  • Projects
    • Structure.CSS
    • NJTools.JS
    • TaskEnjin.PY
    • NetworkEnjin
  • Tools
    • Password Generator
    • Template Processor
    • Iperf 3 for Windows
  • Knowledge-base
  • External Links
    • Microsoft Docs on ACSC Essential Eight
    • AU Government’s Protected Utility blueprint
NJIT.io

NJIT.io

Logrotate cheat-sheet

21 June 2021 By Nathan Jackson

It’s probably installed by default but if not most distribution’s package managers refer to it as logrotate so installing it is pretty straight forward

apt install logrotate
dnf install logrotate
pacman -S logrotate

The main configuration file is:

/etc/logrotate.conf

With (by default) additional configuration files being loaded from the directory:

/etc/logrotate.d

Command to debug configuration file

logrotate -d "{:PathToConfigFile:}"

Command to force run configuration file in verbose mode

logrotate -vf "{:PathToConfigFile:}"

The following is an example configuration for rotating one log file:

/var/log/{:AppName:}.log {
  missingok
  compress
  notifempty
  copytruncate
}

The following is an example configuration for rotating logs file using a wildcard:

/var/log/{:AppName:}/* {
  rotate 30
  daily
  missingok
  olddir "/var/log/{:AppName:}/archive"
  dateext
  compress
}

Common configuration options

OptionDescription
rotate {:NumberToKeep:}Keep {:NumberToKeep:} amount of rotated logs
daily / weekly / monthlyRotate logs regularly
size {:Size:}Rotate logs when they hit {:Size:} in bytes. Can be set as (kilo/mega/giga)bytes with k/M/G
missingokDo not error if log file doesn’t exist
olddir “{:DirectoryPath:}”Places rotated logs into {:DirectoryPath:}
dateextUse date extension in YYYYMMDD format (e.g: 20380120) instead of number format
notifemptyDo not rotate if log is empty
compress /nocompressCompress or not do compress rotated log files
delaycompressWhen using compress will delay compression of the log being rotated until the following rotation
copytruncateDo not delete existing log file, copy file for rotation and truncate contents of existing file
create {:Mode:} {:Owner:} {:Group:}Specify the permissions octal, owner and group when creating a new log file
createolddir {:Mode:} {:Owner:} {:Group:}Create the old directory if it does not exist and set the permissions octal, owner and group to those specified

Filed Under: Linux

Copyright © 2023