29

There's a way to do this?

Guilherme
  • 761

3 Answers3

34

In your logrotate.conf (or the equivilent logrotate.d file), change the line that says "

rotate 10

(your number may be different) to a bigger number. That will tell it to keep that many days of logs. You can make it 36500, which would last you 100 years.

jedberg
  • 2,331
2

I've been looking for this in order to make rotation of my database backups daily, weekly and monthly; so I rotate the file daily but keep the file to do the weekly rotation, and same for the yearly rotation.

Use the copy option. From the manual:

copy

copy Make a copy of the log file, but don’t change the original at all. This option can be used, for instance, to make a snapshot of the current log file, or when some other utility needs to truncate or parse the file. When this option is used, the create option will have no effect, as the old log file stays in place.

-3

Setting aside the point that rotation involves deletion... ;-)

It looks like you can simply add the word 'copy' to the appropriate file (likely in /etc/logrotate.d). For example, an apache2 logrotate script would look like this:

/var/log/apache2/*.log {
    weekly
    missingok
    rotate 52
    compress
    delaycompress
    notifempty
    copy
    sharedscripts
    postrotate
        if [ -f "`. /etc/apache2/envvars ; echo ${APACHE_PID_FILE:-/var/run/apache2.pid}`" ]; then
            /etc/init.d/apache2 reload > /dev/null
        fi
    endscript
}

Try that, and see if it does what you want.