How can I auto archive log files on Windows 2000/2003 Server?

Soldato
Joined
11 Jun 2004
Posts
4,222
Location
Middlesex, London
Hi all,

At work we have a number of Windows 2000/2003 servers which run applciations that produce 10Mb log files every few minutes.

...is it possible to have some sort of job or script that runs every so often and zips up these files and tucks them away in a different folder etc..?

Thanks
 
you would probably want to run some kind of VBScript that uses a command line tool zip application (WinZip does this if you have it licensed), you can then move the zip files to another folder, name them whatever you want etc.
 
another good thing to do with log files (if the app can't manage them itself) is compress the folder with ntfs compression, likelyhood they'll take up about 10% of the previous space
 
Heres a slightly modified version of the VBS script I use for deleting logs older than X days (edit PathToClean and numberOfDays), I just set it to run daily via a scheduled task:
Code:
Option Explicit
On Error Resume Next

Dim fso, PathToClean, numberOfDays, folder, rootFolder, objFolder, objSubfolders, objFiles, folderToClean, folderToCheck, fts, foldersToSkip, skippedfolders
Set fso = CreateObject("Scripting.FileSystemObject")
Set fts = CreateObject("Scripting.Dictionary")

PathToClean = "D:\IISLogs\W3SVC874524"
numberOfDays = 60
foldersToSkip = ""

Set rootFolder = fso.GetFolder(PathToClean)
If Err.Number > 0 Then
	msgbox PathToClean + "is not a valid directory path.  Please correct the path and run the script again.", vbOkOnly, "Path Not Found"
	Wscript.Quit
End If


GetSubfolders(rootFolder)
CleanupFiles(rootFolder)

Set fso = Nothing

Wscript.Quit

Sub GetSubfolders(folder)
	Dim oSubfolder
	Set objFolder = fso.GetFolder(folder)
	Set objSubfolders = objFolder.Subfolders

	For Each oSubfolder in objSubfolders
		If fts.Exists(UCase(oSubfolder.Name)) = False Then
			'Recursively go down the directory tree
			GetSubfolders(oSubfolder.Path)
	
			'Cleanup any files that meet the criteria
			CleanupFiles(oSubfolder.Path)
	
			'Delete the folder if its empty
			CleanupFolder(oSubfolder.Path)	
		End If
	Next
End Sub

Sub CleanupFiles(folderToClean)
	dim objFile
	Set objFolder = fso.GetFolder(folderToClean)
	Set objFiles = objFolder.Files

	For Each objFile in objFiles
		If DateDiff("d", objFile.DateLastModified, Now) > numberOfDays Then
			objFile.Delete
		End If
	Next

	Set objFolder = Nothing
	Set objFiles = Nothing
End Sub

Sub CleanupFolder(folderToCheck)
	Set objFolder = fso.GetFolder(folderToCheck)
	Set objSubfolders = objFolder.Subfolders
	Set objFiles = objFolder.Files

	If objFiles.Count = 0 and objSubfolders.Count = 0 Then
		objFolder.Delete
	End If
	
	Set objFolder = Nothing
	Set objSubfolders = Nothing
	Set objFiles = Nothing
End Sub
 
Heres a slightly modified version of the VBS script I use for deleting logs older than X days (edit PathToClean and numberOfDays), I just set it to run daily via a scheduled task:

CODE

Would you save that code into a .vbs file then? Thanks.
 
Back
Top Bottom