There's a way to do this?
-
Can you tell us why you want to do this? Maybe there's other options... – chmeee Aug 05 '09 at 07: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 08 '16 at 12:43
-
2My 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 02 '16 at 11:20
3 Answers
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.

- 2,301
- 22
- 22
-
8When I did this on a raspberry pi (raspian), it made it freeze every night. Once I cought running processes and open files using the serial console and found out that it tries to rename 100000 of nonexisting files. So beware of it. Unfortunately I don't have more detailed information – Christian Aug 29 '16 at 08:51
-
@Christian best not using auto-increment counters as file name extension, but a date extension. That way the rotated files won't get touched again. – Roger Lehmann Dec 17 '20 at 12:36
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.

- 137
- 2
-
This is the same as the comment below (http://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 02 '16 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.

- 718
- 5
- 9
-
2Assuming 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 05 '09 at 07: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 06 '09 at 04:02
-
2
-
4_"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