Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

There's a way to do this?

share|improve this question
    
Can you tell us why you want to do this? Maybe there's other options... – chmeee Aug 5 '09 at 7:01
    
In my case it would be nice to download big old logs to external storage and keep new ones on the server. So I need a simple log splitter. – sekrett Feb 8 at 12:43
    
My use case for this configuration is: I want to keep my log forever, as I may need it for auditing purposes, BUT I want my files to be rotated so that the current log doesn't grow too big and the rotated ones can be compressed - otherwise, backup of the logs to an external server are too difficult, and inspecting the files also gets too slow. – Rudolf Mayer May 2 at 11:20
up vote 22 down vote accepted

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.

share|improve this answer

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.

share|improve this answer
    
This is the same as the comment below (serverfault.com/a/50186/275485), and does not provide a correct answer; copy does not mean your old files that were rotated are not deleted.. – Rudolf Mayer May 2 at 11:18

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.

share|improve this answer
2  
Assuming that he wants the files to be "rotated" but just never deleting the old files, this won't do it. Adding "copy" to the config stanza means the original file will continue to grow forever but eventually the older copies of the file will be deleted. As I understand it, "copy" is primarily useful when you expect some other process to truncate/delete the original. – Insyte Aug 5 '09 at 7:14
    
Exactly, which is what I thought he was asking for. He specifically asked for a way to "not delete my log files", not a way to "not delete old archives of my log files". Guess I should be more wary of questions that involve just a subject and no body ;-) – Justin Ellison Aug 6 '09 at 4:02
2  
The phrase "after rotation" provides a clue. – Dennis Williamson Aug 15 '09 at 0:06
2  
"Setting aside the point that rotation involves deletion..." Not necessarily. Rotation can involve just compressing the old logs and keeping them, which is what it seems the question asks for. – reflexiv Jan 23 '13 at 22:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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