Wednesday, June 05, 2013

batch backup of logs


rem ----
rem move all the log files to a backup folder
rem ----

SET logpath=C:\mypath\logs
cd /d %logpath%
set 7zexe=C:\scripts\bin\7-ZipPortable\App\7-Zip64\7z.exe

for /f "tokens=1-5 delims=/ " %%d in ("%date%") do set TODAY=%%g-%%e-%%f
mkdir %logpath%\_History_%TODAY%
move %logpath%\*.log %logpath%\_History_%TODAY%
move %logpath%\*.log.* %logpath%\_History_%TODAY%

echo compress the log files in %logpath% %date% %time%

for /D %%i in ("%logpath%\_History_*") do (
  "%7zexe%" a "%%i.7z" "%%i" -mx9 -y
  rem TODO: add 7zip test of archive b4 deleting
  IF NOT ERRORLEVEL 1 rmdir /S /Q "%%i"
)
echo Done compressing Log files - %date% %time%



now on pastebin:

http://paste.ubuntu.com/9624827/


No comments: