LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Logrotate help (https://www.linuxquestions.org/questions/linux-newbie-8/logrotate-help-935407/)

ayush1440 03-20-2012 01:39 AM

Logrotate help
 
Hello Friends,

I have Amazon Cloud account and configured Amazon linux. We are using tomcat on server. Tomcat logs need to rotate.

I successfully configured log rotate and it rotate logs as well. But log rotate creates archive file in same directory..

I want to configure logrotate such a way that it create every year & month directory and then put daily logfiles inside it.

Here is sample of directory structure..

Help would really appreciated.

Code:

--2011 (Year)
 |
 |- Jan (Month)
  |
  |
  | - 01 (Date)
      |
      |- catalina.out
      |- hostmanager**.out
  | - 02 (Date)
      |
      |- catalina.out

Here is my configuration for tomcat

Code:

/tomcat/logs/catalina.out {
 copytruncate
 daily
 rotate 7
 compress
}

Also I require to copy compressed logs to another server. So please help me on that too.

Also welcomed some other tool or advise.

Help would be really appreciated.

Thanks in advance.

EricTRA 03-20-2012 01:53 AM

Hello,

You could add 'dateext' and 'dateformat' to your logrotate configuration to have an additional identifier on your archived logs. Next you could write a shell script to move those files to the correct directory (year/month) after rotating with the postrotate/endscript indicator (have a look at the man page for logrotate).

But... If you're going to copy the compressed files to a remote server why don't you set everything up to use a syslog-ng server which will provide you with what you need (the date structure in directories) and much more additional things like filtering, alert messages and so on.

Kind regards,

Eric

ayush1440 03-20-2012 04:13 AM

Thanks a lot for replying.

Quote:

Originally Posted by EricTRA (Post 4631243)
Hello,

You could add 'dateext' and 'dateformat' to your logrotate configuration to have an additional identifier on your archived logs. Next you could write a shell script to move those files to the correct directory (year/month) after rotating with the postrotate/endscript indicator (have a look at the man page for logrotate).

I understand dateext & dateformat string but is it create directory structure as I said?

Quote:

But... If you're going to copy the compressed files to a remote server why don't you set everything up to use a syslog-ng server which will provide you with what you need (the date structure in directories) and much more additional things like filtering, alert messages and so on.

Kind regards,

Eric
I am on live Production server, So I think this will take long time and may be lots of configuration,. Isn't is there any simple solution like a script to scp & exec after logrotating?

Again thanks for replying, I am new to this things So please help me.

EricTRA 03-20-2012 06:31 AM

Hi,

No, the 'dateext' and 'dateformat' will only add the date to the logfile instead of just a number in the format you indicated using dateformat (consult man page for more detail). This will not create any directory structure. For that part I referenced to writing a script to do that, which script you could put in a cronjob to check for newly created files on a predefined frequency and move said files if they exist to the correct directory and create said directory if it doesn't exist.

I just pointed out syslog-ng as a solution, you could also use rsyslog, which is a lot easier to setup but I'm not sure it will offer you the same functionality (creating directories automatically) as syslog-ng. If you don't want to setup / configure remote logging then you'd have to write your own script to move the files to another server with for example scp withing the postrotate/endscript indicator inside the logrotate configuration.

Kind regards,

Eric


All times are GMT -5. The time now is 08:14 PM.