batch file to zip log file and delete old one.
gzip for windows can be found over here
> http://gnuwin32.sourceforge.net/packages/gzip.htm
put gzip at same folder with batch file.
------content of batch file --------
@echo off
echo Usage: logarchive.bat FolderName Day1 Day2
echo -----------------------------
echo Search files(*.log and *.gz) in folder include it's subfolders
echo if log were accessed by day1 ago then gzip them.
echo if gz were accessd by day2 ago then delete them.
echo -----------------------------
rem parameter check, make sure we got 3 parameter
if [%1]==[] echo parameter1(FolderName) lost, exiting... && goto end
if [%2]==[] echo parameter2(Day1) lost, exiting... && goto end
if [%3]==[] echo parameter3(Day2) lost, exiting... && goto end
rem parameter check, parameter is a folder or not
if not exist %1\nul echo parameter1 isn't a folder name,exiting && goto end
rem parameter check, delete days should large than zip days
if %3 lss %2 echo parameter3(Day2) is less than parameter2(Day1), exiting... && goto end
echo gzip working...
forfiles /P %1 /S /M *.log /D -%2 /C "cmd /c %~dp0gzip @path"
echo -----------------------------
echo del working...
forfiles /P %1 /S /M *.log.gz /D -%3 /C "cmd /c del @path"
:end
> http://gnuwin32.sourceforge.net/packages/gzip.htm
put gzip at same folder with batch file.
------content of batch file --------
@echo off
echo Usage: logarchive.bat FolderName Day1 Day2
echo -----------------------------
echo Search files(*.log and *.gz) in folder include it's subfolders
echo if log were accessed by day1 ago then gzip them.
echo if gz were accessd by day2 ago then delete them.
echo -----------------------------
rem parameter check, make sure we got 3 parameter
if [%1]==[] echo parameter1(FolderName) lost, exiting... && goto end
if [%2]==[] echo parameter2(Day1) lost, exiting... && goto end
if [%3]==[] echo parameter3(Day2) lost, exiting... && goto end
rem parameter check, parameter is a folder or not
if not exist %1\nul echo parameter1 isn't a folder name,exiting && goto end
rem parameter check, delete days should large than zip days
if %3 lss %2 echo parameter3(Day2) is less than parameter2(Day1), exiting... && goto end
echo gzip working...
forfiles /P %1 /S /M *.log /D -%2 /C "cmd /c %~dp0gzip @path"
echo -----------------------------
echo del working...
forfiles /P %1 /S /M *.log.gz /D -%3 /C "cmd /c del @path"
:end
留言
張貼留言