17

Does anyone have a sample logrotate config for redis? This is what I have so far

/var/log/redis/*.log {
        daily
        missingok
        rotate 52
        compress
        delaycompress
        notifempty
        create 640 root adm
        sharedscripts
        postrotate
                ...
        endscript
}

But I'm not sure what to do on the postrotate step. This is on Ubuntu 10.04 LTS.

Simian
  • 1,622
  • 3
  • 17
  • 32

2 Answers2

24

This will probably suffice:

/var/log/redis/*.log {
       weekly
       rotate 10
       copytruncate
       delaycompress
       compress
       notifempty
       missingok
}
Simian
  • 1,622
  • 3
  • 17
  • 32
  • 7
    But how does this request Redis to re-open the log file? ... Oops, I figured it out myself: Redis actually reopens at each log line (see https://github.com/antirez/redis/issues/337#issuecomment-4002868) – jpetazzo Mar 22 '13 at 23:39
  • 1
    copytruncate reuses the same original file(copy then truncate). So even if redis didn't reopen the file it should have been working ok. – c4il Sep 19 '13 at 11:26
  • 2
    Copytruncate is inefficient, and I'd like to avoid it if possible. Is it possible? Looks like it is, so I'll try it. – Marius Gedminas Oct 07 '13 at 11:48
  • Copytruncate doesn't seem to work for redis-sentinel. The log doesn't grow for Sentinel after truncation. – timurb Nov 24 '16 at 07:06
4

I went with

/var/log/redis/*.log {
        weekly
        missingok
        rotate 52
        compress
        delaycompress
        notifempty
        create 0660 redis redis
}

because I don't want copytruncate.

I'm not sure the create line is necessary. It matches the file mode and ownership of the log files typically created by redis-server on Ubuntu (or Debian).

Marius Gedminas
  • 11,010
  • 4
  • 41
  • 39