I am Dale Hayter, a Microsoft and VMware certified Technical Consultant.

My blog has been built up over the years from my experience of working on an IT helpdesk and also from being out on-site.

Batch File to Archive Logs Daily

If you want to archive logs daily then you could use the following batch file.

This could be used to archive ISA logs, IIS logs and the like.

1) Extract 7Zip from here to c:\windows
2) Edit the variables below with your required values.
– logpath1 = Where your log files are stored.
– arcpath1 = Where you want your archived zip files to go.

3) If backing up IIS logs you will need to change the file extension to match
4) Schedule the script to run using task scheduler.
5) If you want to backup every 2 days for example change FORFILES /D -1 to -2 etc.

set _my_date=%date%
set _my_date=%_my_date: =_%
set _my_date=%_my_date::=%
set _my_date=%_my_date:/=_%
set _my_date=%_my_date:.=_%
set logpath1="C:\IISLogs\www\W3SVC1076814132"
set arcpath1="C:\IISLogs\www\W3SVC1076814132\Archive"
set zippath="C:\windows\7za.exe"
cd %logpath1%
FORFILES /D -1 /M *.log /C "cmd /c move @path %arcpath1%"
cd /D %arcpath1%
%zippath% a -tzip logs-%_my_date%.zip %arcpath1%\*.log
del *.log