Tuesday, May 04, 2010

zip, zipper and 7zip log files

For various windows servers I had to decrease the amount of log files on the server itself. Therefore I decided the go with the following strategy:


  • leave 3 days of log files as-is on the server

  • files which are older then 3 day's need to be zipped and I keep a copy on the server

  • files which are older then 60 day's can be deleted because they have already copied onto an additional storage (but this copy is a different szenario and I explain about it in a different blog post)
I accomplished this task with the following components:

  1. 7-zip
  2. forfiles.exe (you can download a rar file from my shared cache website)
  3. Windows Task Scheduler
  4. one bat file

The following 3 lines you multiply as much as needed for each WsSVC[n] folder and save it into a *.bat file.

@echo START - %TIME%
forfiles -p "E:\LogFiles\W3SVC1" -s -m *.log -d -3 -c "Cmd /C 7z a @FILE.zip @FILE"
forfiles -p "E:\LogFiles\W3SVC1" -s -m *.log -d -3 -c "cmd /c del @file"
forfiles -p "E:\LogFiles\W3SVC1" -s -m *.zip -d -60 -c "cmd /c del @file"
@echo DONE - %TIME%
I had to compress 24 folder with log files

All files together had a size 684 MB - well quite a lot for log files but they get very fast very big therefore I really suggest to implement this approach.

For my scripting convenience I've added the installation paths into environment path variable:

  1. Open System properties
  2. Click on Environment Variables
  3. Search for PATH and then click edit
  4. Add both full paths to 7zip and forfiles.exe



Now open your Task Scheduler and create a new Task:







Once you done with the configuration you should make a test run with your task.




The result is that I could save 636 MB on my hard disc on the live server. This space can be used for many other things



No comments:

Shared Cache - .Net Caching made easy

All information about Shared Cache is available here: http://www.sharedcache.com/. Its free and easy to use, we provide all sources at codeplex.

Facebook Badge