How to automate the clean up of JIRA logs (/var/atlassian/application-data/jira/log and /opt/atlassian/jira/logs ) ?
- jira logs
- tomcat logs
- old backup files
If someone is already having script somewhere, please share. Thanks
Hi,
Two things are to do (description below on Unix/Linux) :
To rotate tomcat logs
To purge files older than x days
1) To rotate tomcat logs
- Put this file (attached) log.rotate (c) Copyright 2004 Steven P Kneizys into the logs directory of your java application instance under Tomcat. This script is in Perl (verify that /usr/bin/perl is well the path of Perl language on the server)
- Set the file executable (chmod +x command line for example)
- Modify le file catalina.sh of your Tomcat distribution directory /opt/app/<tomcat-distrib>/bin/catalina.sh replacing 2 time the line (for Tomcat 6.0.x or higher)
>> "$CATALINA_BASE"/logs/catalina.out 2>&1 &
by these 2 lines (no space after "\")
2>&1 | "$CATALINA_BASE"/logs/rmo.log.rotate \ "$CATALINA_BASE"/logs/catalina.out.%Y-%M-%D.log &
- Stop the application ./run.sh stop <instance-name> (verify that the process is well stopped, otherwise kill it)
- Remove the old file catalina.out
- Start the application ./run.sh start <instance-name>
- Tomcat create again an empty catalina.out file on every start, and this file is not touch after. Its modification date is the date of the last start of tomcat. The rotated log files look like catalina.out_log.2013-08-13.txt
Info : on standalone installations, even if a rotation is in place for atlassian logs, catalina.out is filled. To activate the rotation, modify the file /opt/app/atlassian-standalone-appli/apache-tomcat/bin/catalina.sh
2) To purge files older than x days
- Put this file (attached) log.purge (c) Copyright 2004 Steven P Kneizys into the logs or save directory to purge. This script is in Perl (verify that /usr/bin/perl is well the path of Perl language on the server)
- Set the file executable (chmod +x command line for example)
./log.purge "." 10 "(catalina.2)(.)*(.log$)"
Login as <tt>root</tt>Edit the crontab file crontab -eAdd the line below (set your proper path and file name regex of logs or files to purge)5 1 * * * su - app -c 'cd /opt/app/tomcat/jira/logs; ./rmo.log.purge "." 10 "(catalina.out.2)(.)*(.log$)" >/dev/null 2>&1'Save it
5 1 * * * su - app -c 'cd /opt/app/atlassian-crowd-2.3.4/apache-tomcat/logs; \ ./rmo.log.purge "." 10 "(catalina.2)(.)*(.log$)" >/dev/null 2>&1' 5 1 * * * su - app -c 'cd /opt/app/atlassian-crowd-2.3.4/apache-tomcat/logs; \ ./rmo.log.purge "." 10 "(manager.2)(.)*(.log$)" >/dev/null 2>&1' 5 1 * * * su - app -c 'cd /opt/app/atlassian-crowd-2.3.4/apache-tomcat/logs; \ ./rmo.log.purge "." 10 "(localhost.2)(.)*(.log$)" >/dev/null 2>&1'
Hope that will help you, best regards.
log.rotate
#!/usr/bin/perl # (be sure to set this to your perl path and 'chmod +x' this script.) # spk.log.rotate script for piped logging # # Copyright 2004 Steven P. Kneizys # # sample usage for piping from program "program": # # ... program | spk.log.rotate /path/to/logs/%Y-%M-%D-logname_log # $logname_template = $ARGV[0]; $file = ""; while(<STDIN>) { $line = $_; $time = time; if (($file eq '') || ($time gt (60 + $last_time))) { chomp($mydate=`date +%Y-%m-%d`); $last_time = $time; (@date)=split(/-/,$mydate); $temp = $logname_template; $temp =~ s/%Y/$date[0]/gi; $temp =~ s/%M/$date[1]/gi; $temp =~ s/%D/$date[2]/gi; } if ($file ne $temp) { if ($file ne '') {close MYFILE;} $file = $temp; open MYFILE,">>$file"; select((select(MYFILE), $| = 1)[0]); # autoflush } print MYFILE $line; } if ($file ne '') {close MYFILE;}
log.purge
#!/usr/bin/perl # (be sure to set this to your perl path and 'chmod +x' this script.) # # Script name: spk.log.purge # Purge files in a directory (not a directory tree!) based on age. # Copyright 2004 Steven P Kneizys # if (@ARGV < 3) { #Requires three input parameters, fourth is optional print "USAGE: perl spk.log.purge DirectoryPath MaxAge \"pattern\" [test]\n"; print " DirectoryPath = Directory to purge from.\n"; print " MaxAge = days of keep files \n"; print " \"pattern\" = pattern to match for file names\n"; print " [test] = optional parameter to print instead of delete.\n"; exit 1; } $dir = $ARGV[0]; $maxage = $ARGV[1]; $pattern = $ARGV[2]; opendir(DIR, $dir); foreach (readdir(DIR)) { $path = "$dir/$_"; if ((-f $path) && (-M $path > $maxage) && ($_ =~ $pattern)) { if ($ARGV[3] =~ /test/i) { print `ls -al $path`; } else { unlink $path; # delete the file } } } closedir(DIR);
We also have a KB on this that will also help: https://confluence.atlassian.com/display/JIRAKB/How+to+Rotate+Catalina+Log+File
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Nic Brough -Adaptavist- ,
Thanks for the reply, I'm a bit new to linux.
due to large number of old logs, our disk space is getting low, we are looking for the same kind of solution,
If possible can you please more elaborate on the Cron expression,
Thanks,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What do you need in "elaboration"?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Cron expression to delete the files on automaton based number of days older
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Don't ever do things like messing with Cron unless you fully understand what they are doing. You should read a tutorial or docs on Cron (and "find" if you're going to be using a command like the one I gave earlier)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sure, Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.