Tuesday, November 8, 2011

Archive (Backup and Delete) IIS Logs in SharePoint

IIS logs are the requests from clients, and written into text-based log files. It captures every web page/image/script requests. By default, IIS logs stored in C:\ of WFE servers. If SharePoint is being accessed a lot, It may cause disk space problem for your OS drive so quickly. So we can change this log path. Here is how:
  1. Go into IIS Manager for each WFE. (Start > run > Inetmgr)
  2. select the server name in the Connections panel on the left.
  3. In the Features view shown in the middle panel, select Logging.
  4. For the log file, change the directory to a more suitable drive and folder. For example, I’ve changed the path for the log files to D:\Logs\IIS.
sharepoint 2010 iis logs location

How about backing up them Monthly and deleting old logs?
Its a good idea to backup and clean IIS Logs every Month. These Logs are highly compressible up to 500%!!! (Meaning 500 MB file to 5MB file).

1. Download and import the PowerShell community Extension (for write-zip cmd-let)
2. Write the script to Zip and Delete IIS Logs
3. Schedule the script to run on every month ( or based on your schedule)

Step 1: Download and import the PowerShell community Extension
Download the PowerShell community Extension from http://pscx.codeplex.com/, and then unblock it(Right click the downloaded .zip file > go to Properties > click on "Unblock" button)

Fire up PowerShell, Get in to your modules folder, typically it would be:C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
cd $PSHome\Modules

Extract the PowerShell community Extension Zip file to a folder, Say: pscx . Now, Import the downloaded modules:
import-module Pscx


Step 2: Write the script to Zip and Delete IIS Logs
Now the next step: Writing PowerShell script to Zip and delete the Old log files, Here is the script:

setExecutionPolicy RemoteSigned #important
$date=get-date -UFormat %m-%d-%y
write-zip -Path C:\Logs\IIS -Outputpath C:\Logs\$date.zip
move-item c:\Logs\$date.zip D:\IISLogBackup\
get-childitem C:\Logs\IIS -include *.log -recurse | remove-item
Place the above script in to a file, Say: d:\Scripts\IISCleanup.ps1

Step 3: Schedule the script to run on every month
Finally, We need to schedule the script in Windows Task scheduler. Go to Start > All Programs > Administrative tools > Task Scheduler, and create the task to run the script at d:\Scripts\IISCleanup.ps1.
powershell.exe D:\scripts\IISLogsClear.ps1 If you get exceptions like "File not found.." then add the paths D:\Scripts, PowerShell's path in System Environment variable.

Update: Related to this, there is a codeplex utility to  compress and move SharePoint Logs (Not IIS Logs): http://dlc.codeplex.com/

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

1 comment :

  1. HI i would like to say thanks to you, i am searching this type of article, it's helped lot...


Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...