Question

I have a script where I'm fetching the logs from the tomcat and sending that into the my cloud resource. Everything works well, but I have a problem when my tomcat rotates the log.

When the logs get rotated its been prefixed with date ( log gets rotated every day ). Since my script just runs every half an hour I may miss the logs when it gets rotated, because I'm fetching the logs with their static name, in the example logfile.log.

Before getting rotated the file will look like this :

logfile.log

After getting rotated, it will look like this :

logfile.log.2012-10-09

Are there any ways to get rid of this problem?

Edit:

My script :

cp /tomcat/logs/$logname $fileName 
gzip $fileName
s3cmd put $fileName.gz s3://x.x.x.x.x/$folderName

Thanks in advance.

Was it helpful?

Solution

I think the best way to backup you logs is to do a check according to the mtime of the logfiles.

You can keep the log file mtime of the last backup somewhere, then check both rotated log files and current log file. If there is a rotated log file that newer then the last mtime stored, you could append the current log file to the rotated one and then backup. If only current log file is newer, then just backup it.

The mtime of the file could be retrieved by: LC_ALL=C stat logfile.log | grep '^Modify' | cut -d: -f2-, or the unix timestamp by date "+%s" --date="$(LC_ALL=C stat logfile.log | grep '^Modify' | cut -d: -f2-)"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top