PDA

View Full Version : Need help with configuring logrotate.conf file



marathonequipment
07-16-2008, 09:06 AM
hello I am looking for some guidance on configuring my logrotate.conf file to do the following:

Rotate logs daily
Add date information to log names e.g.: access_log_2008_07_16
gzip logs into monthly archives
Maintain six months worth of logs on server


I currently have the following in my file:


# Comment in order not to compress your previous log files with gzip
compress
missingok
rotate 250

/var/log/httpd/access_log /var/log/httpd/agent_log
/var/log/httpd/error_log /var/log/httpd/referer_log
/var/log/httpd/ssl_request_log
/var/log/httpd/ssl_engine_log
/var/log/httpd/secondarysite_access_log {
sharedscripts
copytruncate
size=5M
prerotate
/bin/web_logs.sh
endscript
}

/var/log/maillog {
size=500k
}

If the archiving is too much I understand and would be good with just knowing how to add the date formatting to the logs and rotate daily keeping six months of logs at a time.

Thanks! -Rick

bruce.binder
07-16-2008, 12:12 PM
Rick:

* Rotate logs daily

Use the option "daily" in your config file.

* Add date information to log names e.g.: access_log_2008_07_16

Use the option "dateext" in your config file.

* gzip logs into monthly archives

The option "compress" will compress each individual log file, but if you want a daily file and then those files compressed into a monthly archive, I think you'll have to call a separate script with prerotate or postrotate.

* Maintain six months worth of logs on server

Use the option "rotate 183" in your config file. 183 is six month's worth of days. The option uses the number as the count of how many files it preserves, so if you are rotating monthly, you would use "rotate 6" instead.

I know WH doesn't provide man pages, but the man page for logrotate is pretty informative, if you can find it on the web.

E.g. http://www.linuxcommand.org/man_pages/logrotate8.html

I hope this helps,
--
Bruce

marathonequipment
07-17-2008, 08:58 AM
Hey that does help, a lot!

I wonder if I couldn't do something like this to first store daily logs for 6 months and then to create a monthly archive that will rotate every 6 months.


# Comment in order not to compress your previous log files with gzip
compress
missingok
rotate 183
daily
dateext

/var/log/httpd/access_log /var/log/httpd/agent_log
/var/log/httpd/error_log /var/log/httpd/referer_log
/var/log/httpd/ssl_request_log
/var/log/httpd/ssl_engine_log
/var/log/httpd/nexgenbalers_access_log
/var/log/httpd/parts1stop_access_log {

sharedscripts
copytruncate
prerotate
/bin/web_logs.sh
endscript

postrotate
monthly
rotate 6
endscript
}

/var/log/maillog {
size=500k
}

include /etc/logrotate.d

If not I can always zip up my logs by month manually.

BTW Bruce I noticed you live in San Diego. I used to be the Graphic Designer for Legoland. I've since moved but man I miss SD.

Thanks!

marathonequipment
07-28-2008, 10:04 AM
Well I thought I had it fixed but i'm still not getting date extensions on my files. Here's what I'm using now.


# email errors
errors email_myemail@domain.com

# uncomment this if you want your log files compressed with gzip
compress

missingok

# Keep approx six months of log files
rotate 183

#Rotate log files daily
daily

# Add date extension at the end of filename
dateext

/var/log/httpd/access_log /var/log/httpd/agent_log
/var/log/httpd/error_log /var/log/httpd/referer_log
/var/log/httpd/ssl_request_log
/var/log/httpd/ssl_engine_log
/var/log/httpd/site2_access_log
/var/log/httpd/site3_access_log {
sharedscripts
copytruncate
prerotate
/bin/web_logs.sh
endscript
}

/var/log/maillog {
size=500k
}

# packages can drop log rotation information into this directory
include /etc/logrotate.d

Does anyone here know why the dateext command isn't working?

Thanks!

bruce.binder
07-30-2008, 01:16 PM
Rick:

What behavior are you seeing? Are the logs rotating and compressing, but they just have .1 .2 etc. instead of the date? Or are they failing to rotate at all?

--
Bruce

marathonequipment
08-14-2008, 01:26 PM
Bruce,

Sorry for the delay, the logs files are rotating correctly but just like you mentioned above they are just numbered .1 .2 etc.

I'm assuming deteext isn't working properly but I don't have a clue how to check this.

Any suggestions?

thanks!

bruce.binder
08-14-2008, 06:03 PM
Rick:

I added dateext to my logrotate.conf file and then I manually ran logrotate in debug mode:


logrotate -d /etc/logrotate.conf

Unfortunately, I got the error message:


error: /etc/logrotate.conf:12 unknown option 'dateext' -- ignoring line

I did a little googling and I think logrotate needs a patch in order to support dateext. I guess our version doesn't have it.

I think our options are


Ask Westhost to install the patched logrotate.
Download (and possibly build) a patched version.
Write a postrotate script to do the renaming.
Live with it as-is.


Sorry,
--
Bruce

marathonequipment
08-20-2008, 10:07 AM
Thanks for looking into it Bruce. Maybe I can persuade someone at Westhost to install the patch.

I appreciate it!

Rick