Exchange Server

How to Move and Truncate Logs in Exchange Server 2013

In this blog will discuss how to manually move and truncate Logs in Exchange server 2013.

Here you can find some ways to truncate/move these logs, i.e.

Transaction logs

Queue Database

Transport Logs

IIS log files

Logging Folder

1. Backup

Backup is the best approach, once the full or incremented backup has been successfully performed the truncation of transaction logs that are no longer necessary to database recovery.

Here is a very good article on backup setting with Windows Server Backup: https://technet.microsoft.com/en-us/library/dd876854(v=exchg.160).aspx

2. Enabled Circular Logging

When the circular logging is enabled, the transaction log is cleared right after the transactions have been moved to the database. Once the circular logging is enabled, then the additional log files are not created.

 

Circular Logging is enabled in the EAC as follows:

Here is a good article for Configure circular logging for a mailbox database: https://technet.microsoft.com/en-us/library/dn756374(v=exchg.150).aspx

3. Moving Transaction Logs

Now we can move the Transaction logs along with the database to another location/drive as per requirement.

You can use cmdlet Move-DatabasePath to do this.

Here is an example of moving the database MDB001 and transaction logs to the corresponding directories on the disk D:\:

Move-Databasepath “DB1” –EdbFilepath “C:\DB1\DB1.edb” –LogFolderpath “C:\DB1\DB1\logs\”

‘’’’’’’’’’’’’’’’’image———-

Queue Database

 

You can free up some space by moving Queue database. A queue is a temporary holding location for messages that are waiting to enter the next stage of processing. The each queue represents a logical set of messages that a transport server processes in a specific order.

The location of the queue database and its transaction logs is managed by the keys in the XML configuration file %ExchangeInstallPath%Bin\EdgeTransport.exe.config.

To move it to another location. Here is a very good article to change the location of the queue database: https://technet.microsoft.com/en-us/library/bb125177(v=exchg.150).aspx

Transport Logs

The Transport logs provide information about what’s going on the transport pipeline. A detailed article about Transport logs here: https://technet.microsoft.com/en-us/library/dd302434(v=exchg.150).aspx

Here is a list of Transport logs available in Exchange Server 2013:

  • Agent logs
  • Connectivity logs
  • Message tracking and delivery reports
  • Pipeline tracing
  • Protocol logs
  • Routing table logs

 

To change the path to Protocollogs using EAC:
servers\servers\select_a_server\transport logs\protocol log

To change the path to Message Tracking using EAC: servers\servers\select_a_server\transport logs\message tracking log.

IIS log files

The IIS log contains information of activesync and these IIS logs can become too large in size. Below we see how to delete or move them to another drive automatically?

Automatic Log Removal

For best practice run daily the below Powershell-script with scheduler you can change the path to the logs and all IIS logs older than 30 days will be automatically deleted.

set-location c:\inetpub\logs\LogFiles\W3SVC1\ foreach ($File in get-childitem) {    if ($File.LastWriteTime -lt (Get-Date).AddDays(-30)) {       del $File   } }

You can also run the PoSH script via the scheduler as follows:

  1. Create a task in the scheduler
  2. Create action: start a program
  3. In the field program/script:C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
  4. In the field add arguments(optional): -command “path-to-script\name.ps1”

 

Moving Logs to Another Location

First, Open IIS Manager from Administrative Tools and select Default Web Site.

Then, Open Logging by double-click on Logging icon

After that change the log storage location in directory

And then, save the changes. The next log file will be written to the new location.

The same can be done in Powershell:

Import-Module WebAdministration

Set-ItemProperty ‘IIS:\Sites\Default Web Site’ -name logfile.directory «D:\IISLogs»

Here is the command for moving the Logfiles for Exchange Back End.

Import-Module WebAdministration
Set-ItemProperty ‘IIS:\Sites\ExchangeBackEnd’ -name logfile.directory “D:\IIS\LogFiles\ExchangeBackEnd” -verbose

 

Logging Folder

Logging folder which is located in C:\Program Files\Microsoft\Exchange Server\V15\Logging by default. The number of logs of different services are stored here and they can consume a notable amount of the disk space. Diagnostic and performance log files can take quite a lot of space. They are located in C:\Program Files\Microsoft\Exchange Server\V15\Logging\Diagnostics folder

There is a simple solution of this problem: run automatic removal via the scheduler daily and all logs from these folders older than 20 days won’t disturb you any more:

gci ‘C:\Program Files\Microsoft\Exchange Server\V15\Logging’,’C:\inetpub\logs’ -Directory | gci -Include ‘*.log’,’*.blg’ -Recurse | ? LastWriteTime -lt (Get-Date).AddDays(-20) | Remove-Item

 

to remove only diagnostics logs:

gci ‘C:\Program Files\Microsoft\Exchange Server\V15\Logging\Diagnostics’ -Directory | gci -Include ‘*.log’,’*.blg’ -Recurse | ? LastWriteTime -lt (Get-Date).AddDays(-5) | Remove-Item

By following above steps you can easily move and truncate logs in Exchange Server 2013.

Leave a Reply

Your email address will not be published. Required fields are marked *