We are running a number of Apache Tomcat servers. A good portion of the logs rollover as they should based on the hour or at the end of the day. However, there are still a number that remain locked by Apache Tomcat, or web services.
Have actually logged this as a bug at - http://sourceforge.net/p/sevenzip/bugs/1488/
Have seen dbenham's awesome post (NOTE: it is under the second "EDIT" header, to what I am referring to) about how to deal with an in-use file. However, I am still running into contention with in-use files. I know WinZip Command-line maybe an option, but I really don't want to use that.
We have a nightly process to come in, which is much has more functions than this, but for illustration we are going to use the following:
FOR /r "C:\tomcat\logs" %%X IN (*) DO (
7za a -y D:\17\%%~nxX.zip %%X
)
PAUSE
So, what we see as a result are a number or 22-byte, empty zip files. Yes, we know not to zip an "in-use" file, but if it comes in does a directory list, we see this issue.
Is there something that we can do?
Volume in drive D is New Volume
Volume Serial Number is A476-BD38
Directory of D:\17
03/07/2015 02:05 PM <DIR> .
03/07/2015 02:05 PM <DIR> ..
03/07/2015 02:05 PM 403 catalina.2015-03-06.log.zip
03/07/2015 02:05 PM 22 catalina.2015-03-07.log.zip
03/07/2015 02:05 PM 22 host-manager.2015-02-23.log.zip
03/07/2015 02:05 PM 22 localhost.2015-02-23.log.zip
03/07/2015 02:05 PM 22 manager.2015-02-24.log.zip
03/07/2015 02:05 PM 22 probe.log.zip
6 File(s) 513 bytes
2 Dir(s) 51,783,634,944 bytes free
Normally, I would not really care about 22-byte files, but we have to watch them as they are being sent nightly to a vendor for report processing.
Looking at the script in how we are using it, we have:
REM SET VARIABLES
FOR /f "tokens=2-4 delims=.:/ " %%a IN ("%date%") DO SET CurrentDate=%%c-%%a-%%b
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /r "D:\17" %%X IN (*) DO (
SET FileName=%%~nxX
FOR /f "tokens=2-4 delims=.:/ " %%a IN ("%%~tX") DO SET FDate=%%c-%%a-%%b
REM CHECK FOR UNLOCKED FILE
REM https://stackoverflow.com/a/10520609/1333331
2>nul ( >>"D:\17\!FileName!" (call )) && (
REM DO STUFF HERE
IF "%CurrentDate%" NEQ "!FDate!" (
IF %%~zX GTR 0 (
ECHO ARCHIVING "D:\logs\!FileName!" >>%logfile%
7za.exe -tzip -y a "D:\Archive\some.zip" "D:\17\!FileName!" && DEL "D:\17\!FileName!"
)
)
REM END OF UNLOCKED ZONE
) || (
ECHO FILE IS LOCKED
)
)
ENDLOCAL
Thanks!