Cleaning up transaction logs created when RecoveryManager Plus performs any backup and restoration operations

Cleaning up transaction logs created when RecoveryManager Plus performs any backup and restoration operations

Problem   

Once you deploy on-premises Exchange, the available disk space will decrease due to the increase in logs generated by the mailboxes. This problem of large log sizes is predominant in Exchange versions 2013 and above.

When you install RecoveryManager Plus to back up your on-premises Exchange mailboxes, the product uses the Exchange Web Services (EWS) API to access mailboxes located on the Exchange Server. Every time the product accesses these APIs for any action like taking a backup or performing a restoration, Microsoft Exchange creates a log. If your environment has a large number of mailboxes and you have scheduled daily incremental backups, the available disk space will reduce quickly.

In addition to logs generated by the server when a backup operation is run, there are plenty of logs that are generated on a daily basis by the Exchange server. Unless you regularly clean up old log files, it is very common for mailbox databases to automatically unmount and cause disruptions to your users with the error 452 4.3.1 Insufficient system resources error.


Solution   

The most efficient way in which this problem can be solved is by periodically clearing old logs created by the Exchange server due to backups and other normal activity. Since these logs are created by the Microsoft Exchange server, these cannot be deleted by RecoveryManager Plus.

This article will elucidate how you can automate clearing any transaction log files.

Disclaimer: Please be aware that RecoveryManager Plus does not directly create any logs in your Exchange server nor does it delete existing logs. This article explains how you can automatically clear logs that have been and will be created by your Exchange server.

 Step 1: Creating the required PowerShell script   

  1.  Create a PowerShell script. 

                # Set execution policy if not set

                $ExecutionPolicy = Get-ExecutionPolicy

                if ($ExecutionPolicy -ne "RemoteSigned") {

                    Set-ExecutionPolicy RemoteSigned -Force

                }

                # Cleanup logs older than the set of days in numbers

                $days = 2

 

                # Path of the logs that you like to cleanup

                $LogPaths = "C:\Program Files\Microsoft\Exchange Server\V15\Logging\Ews\"

 

                # Clean the logs

                Function CleanLogfiles($TargetFolders) {

                 foreach ($TargetFolder in $TargetFolders) {

                    Write-Host -Debug -ForegroundColor Yellow -BackgroundColor Cyan $TargetFolder

 

                    if (Test-Path $TargetFolder) {

                        $Now = Get-Date

                        $LastWrite = $Now.AddDays(-$days)

                        $Files = Get-ChildItem $TargetFolder -Recurse | Where-Object { $_.Name -like "*.log" }

| Where-Object { $_.lastWriteTime -ge "$lastwrite" } | Select-Object FullName  

                        foreach ($File in $Files) {

                            $FullFileName = $File.FullName

                            Write-Host "Deleting file $FullFileName" -ForegroundColor "yellow";

                            Remove-Item $FullFileName -ErrorAction SilentlyContinue | out-null

                        }

                    }

                    Else {

                        Write-Host "The folder $TargetFolder doesn't exist! Check the folder path!"

-ForegroundColor "red"

                    }

                 }

                }

                CleanLogfiles($LogPaths)

 

Note 1: In this sample script, we have provided the value 2 in line 7 of the script. Depending on the value provided here, logs older than the number of days of the provided value will be deleted.You can modify the value to any number depending on your incremental backup frequency configured. If you have a daily scheduler, we recommend you provide the value 1. Likewise, use the values 7 and 31 if your incremental backup frequency is weekly and monthly, respectively.

Note 2: If you have installed Exchange in a different directory instead of the default path, provide the path in line 10 of the script. Depending on the version of your Exchange Server, the value ../V15/... has to be changed to the relevant number. If you want to periodically clear other logs in your system, add the location of the logs at the end of $LogPaths separated by a comma.

  1. Store the script as CleanupLogs.ps1 and place it in the C:\Scripts\ folder. If you do not have a Scripts folder, create one in the C:\ drive.

 

Step 2: Automate the log cleanup procedure using Task Scheduler   
  1. Start Task Scheduler

  1. Click on Task Scheduler Library from the left-pane and click New folder from the right-pane. Name the folder as RecoveryManager Plus and click OK.

  1. Click the newly created Exchange folder from the left-pane and click Create Task from the right-pane.

  1. A Create Task window pops-up.

  1. Click on the General tab.

  1. In the Name field, enter EWSLogsCleanup.

  1. Under Security options,

    • Click on the Change User or Group button and select SYSTEM.

    • Enable Run with highest privileges.

    • Select Configure for Windows Server 2016 if you have a Windows Server 2016. If you have a different Windows Server version, select the appropriate one.


  1. Click on the Triggers tab and click New.

  1. In the Settings section, select Daily and provide the time at which you want the log cleanup to run in the Start field. Make sure that it’s Enabled and click OK.

Note: In this example, we have selected Daily. However, if you have scheduled RecoveryManager Plus to perform incremental backups weekly or monthly, you can change it accordingly.

  1. Click on the Actions tab and click New.


  1. In the Settings section,

    • Select PowerShell.exe in the Program/script field.

    • Enter -ExecutionPolicy Bypass C:\Scripts\CleanupLogs.ps1 in the Add arguments (optional): field.

    • Click OK.

  1. Click OK.

The task has now been scheduled and your Exchange EWS logs will now be cleared at the specified time and frequency.


Step 3: Manually run and test the cleanup Exchange logs task   
  1. Click the created task CleanupLogs from the middle-pane and Click Run from the right-pane.

  1. You can check the status of the last run operation in the Last Run Result column in the middle-pane.

  1. Check if the CleanupLogs task cleared the logs in the following folder(s).
    C:\Program Files\Microsoft\Exchange Server\V15\Logging\Ews\

Note: If you have added additional logs to be cleared using the script (line 10 of the script), check if those logs have also been successfully cleared.

Note: Please be aware that RecoveryManager Plus does not directly create any logs in your Exchange server nor does it delete existing logs. This article explains how you can clear logs that have been and will be created by your Exchange server.

 


                  New to ADManager Plus?

                    New to ADSelfService Plus?

                      • Related Articles

                      • Does RecoveryManager Plus support TLS v1.2 protocol?

                        Yes, RecoveryManager Plus supports TLS v1.2. The product can be configured to use only this protocol by following the steps mentioned below. Before you proceed, please enable SSL and apply an SSL certificate in RecoveryManager Plus as explained in ...
                      • How to install SSL certificates for RecoveryManager Plus

                        RecoveryManager Plus supports an SSL connection to ensure the security of data transferred between the browser and the product server. Protecting data transferred during remote access requires a secure connection between the web browser and the ...
                      • DNS node restoration

                        A DNS zone is comprised of several DNS nodes housing domain-related information. RecoveryManager Plus can back up all DNS nodes in a particular DNS zone and restore them to any previously backed-up state. This guide provides a step-by-step approach ...
                      • How to find deleted objects in Active Directory?

                        Problem If you do not have the AD Recycle Bin enabled, it is impossible to find out what objects were deleted. You can only find the deleted objects when it causes operational issues. This post will explain how you can ascertain the deleted objects ...
                      • Restoring your default domain policy

                        Every setting you configure in the default domain policy applies to every user and computer account in the domain, unless these settings are overwritten by other domain GPOs having higher precedence or by GPOs linked to OUs. When unintended changes ...