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 ADSelfService Plus?

                    • Related Articles

                    • How to backup Active Directory using RecoveryManager Plus

                      Active Directory (AD) is crucial to the day-to-day operations of most modern organizations, as it manages users, computers, applications, and resources within a network. It is designed to centralize and streamline access control to ensure only ...
                    • A guide to backing up AD users using RecoveryManager Plus

                      Active Directory (AD) is the foundation of most enterprise networks, providing a central repository for authentication, authorization, and user management. User accounts in AD form the backbone of identity management, enabling secure access to ...
                    • How to configure backup repositories for your backups in RecoveryManager Plus?

                      RecoveryManager Plus provides support for multiple repositories to store your Active Directory, Entra ID, Microsoft 365, Exchange, Google Workspace, and Zoho WorkDrive backups. This post will explain how you can configure these repositories in ...
                    • How to restore AD groups using RecoveryManager Plus

                      Active Directory (AD) groups play a crucial role in managing user permissions and access control in an organization's network. They enable administrators to efficiently manage user permissions, access control, and resource sharing by grouping users ...
                    • Understanding backup archiving

                      Backup archiving lets you store backed up files for long-term retention, which can be indexed and viewed in the backup explorer menu when required. This process streamlines backup management and optimizes storage usage by keeping only the most recent ...