38

The Geek Stuff has an example about logrotate. copytruncate will copy and truncate the original log file.

Then why we should use create? The original log file has not been removed.

/tmp/output.log {
  size 1k
  copytruncate
  create
  compress
  compresscmd /bin/bzip2
  compressext .bz2
  rotate 4
  maxage 100
}

Another question is what is the use of maxage 100? The rotate 4 directive will delete old log files after 4 rotation.

  • 4
    Yes, that doesn't make sense and man logrotate even says so: "copytruncate: [...] When this option is used, the create option will have no effect, as the old log file stays in place." – Ulrich Schwarz Mar 5 '12 at 8:16
  • 1
    maxage 100 will delete rotated files when they become over 100 days old and the current file is rotated; even when fewer than 4 rotated files exist. – Lutz Prechelt Nov 18 '16 at 18:28
52

That is probably a mistake, it is found only in one example on that tutorial. All other examples have copytruncate without the create option. Also logrotate man page states that It will be actually ignored:

copytruncate

Truncate the original log file to zero size in place after creating a copy, instead of moving the old log file and optionally creating a new one. It can be used when some program cannot be told to close its logfile and thus might continue writing (appending) to the previous log file forever. Note that there is a very small time slice between copying the file and truncating it, so some logging data might be lost. When this option is used, the create option will have no effect, as the old log file stays in place.


Regarding maxage, I think it can be useful for example for logfiles which can be empty for few rotation periods (days/weeks/months) — if you use notifempty, empty logfile will not be rotated, so you can have too old rotated files still in place.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.