5

In a normal logrotate.d configuration file, is there any way to set an unlimited amount of potential logs?

The only thing I can seem to come up with is setting it at some crazy number that will never be met. Something like:

/var/log/app/* {
  missingok
  weekly
  copytruncate
  rotate 10000000000
  compress
  notifempty
  olddir /var/log/app/old
}

But that seems pretty hacky to me.

stewbert
  • 51
  • 1
  • 5
  • Interesting question. I seem to recall that `rotate 0` only keeps the current log. Have you tried `rotate -1` or omitting it completely? – Anders R. Bystrup Feb 26 '13 at 10:16
  • You already found a solution, now lets cross fingers and assume logrotate uses a 64bit integer to store the rotate value. – ypnos Feb 26 '13 at 10:21
  • @ypnos The data type for rotation count is `int`, which is only guaranteed to be at least 16 bits. That limits you to 2\*\*15-1=32767. In practice, however, it is commonly 32 bits today, yielding 2\*\*31-1=2147483647. Anyway, even with just a 16 bit int it should last for the foreseeable future: with one log per day, that's almost 89 years. – tobbez Apr 11 '18 at 10:39

1 Answers1

4

From UNIX logrotate man page:

rotate count

Log files are rotated times before being removed or mailed to the address specified in a mail directive. If count is 0, old versions are removed rather then rotated.

So I guess you need to write a huge number to work.

fedorqui
  • 275,237
  • 103
  • 548
  • 598
  • Sorry, I should have mentioned that I checked the manpage first. It didn't say anything there but I was just wondering if anyone had a better idea. Someday, that huge number could be met :) I guess one idea could be a cron job that moves the logs to an /old/old folder when it gets up to a certain count... – stewbert Feb 26 '13 at 10:23
  • OK! So I re-worked checking the man page : ) Well, I think this is a good idea, sure. You can create this script checking the number of files in the dir, something like `if [ $(ls -1 /dir | wc -l) -ge $BIG_NUMBER ]; then bla bla bla`. I think it is not good to store bilions of log files all together. If you need information, it is better to store in different places so that if something happens to the filesystem, you can recover it. What about full backups from time to time, so you can recover it from backup if necessary? – fedorqui Feb 26 '13 at 10:26
  • That's the eventual plan, of course. This is more of a bandaid to the real problem (an application that is generating logs at an alarming rate). For the actual application owner I just know they would sleep better at night if there as an "unlimited" setting that could be used until a "real" solution can be implemented (stop the application from generating so many damned logs! Right now it will be rotating 20MB logs every 10-15 minutes...) Thanks! I'll give you the answer. – stewbert Feb 26 '13 at 10:36
  • Wow! So it is definitely a matter of checking the application. You should also increase `size` to something quite big. Again, man page does not clarify the limit, but 20MB should be ok. Good luck, @stewbert! – fedorqui Feb 26 '13 at 10:38