Script: Backup-DBs.p1 – Using Windows Backup for Exchange 2010

I was working with a client on a recent project and they have a Dell EqualLogic SAN and the ASM/ME (Auto Snapshot Manger/Microsoft Exchange) software. After we set it up we quickly realized that the transaction logs weren’t being truncated. We did some research and couldn’t find anything about log truncation in documentation. Upon further research I found out that “ASM/ME was not designed for backups” per this thread. So not only does it not tell Exchange to truncate transaction logs it also doesn’t update the backup dates, available when doing [Get-MailboxDatabases –Status].

So we have good snapshot and recovery support but no solution to truncate transaction logs, unless we want to enable continuous replication circular logging (CRCL) (more on that here). But, if we enabled CRCL we lose support for point-in-time recovery. The other snapshot based solutions I’ve worked with all took snapshots of the database, transaction logs from the last snapshot, and then told Exchange to truncate the logs. So we decided to use Windows Backup to do a weekly backup, which should then trigger truncation of logs.

Well this turned out to not be as easy as I expected due to the fact that each server in the DAG host passive copies of other database and Windows Backup requires you disable the VSS Writer. Furthermore, if we disabled the VSS Writer then ASM/ME, as do other solutions per my research, snapshots fail.

If you don’t have the VSS Writer disabled you will get the following error when you try to use wbadmin.exe

Retrieving volume information…
This will back up volume DB-C(I:) to \\COSRVBK01\backups\COSRVEX01\Users-C.
The backup operation to \\ COSRVBK01\backups\COSRVEX01\Users-C is starting.
Creating a shadow copy of the volumes specified for backup…
The consistency check failed for the component 738edacb-bdec-4735-85c8-a6fd22105ba1 (Microsoft Exchange Server\Microsoft Information Store\COSRVEX01\738edacb-bde
The backup of the application Exchange failed.
Detailed error: The parameter is incorrect.

Changing HKLM:\Software\Microsoft\ExchangeServer\v14\Replay\Parameters\EnableVSSWriter=0 then restarting the Exchange Replication service fixes this issue. Given the need to check for this value and change it back, so ASM/ME still works, and to make sure the database are active locally I ended up writing the script below.

[String] $Server = $env:computerName)

$BackupShare = "\\COSRVBK01\backups\COSRVEX01\" #Including trailing backslash
$Databases = @("Users-A","Users-B","Users-C")

$RequireLocal = $False # Script will skip any DBs that aren't active locally

# HKEY_LOCAL_MACHINE\Software\Microsoft\ExchangeServer\v14\Replay\Parameters\EnableVSSWriter = 0
# If the Exchange server host any passive copies this key must be set to 0 or Windows Backup will fail
# Setting this to 0 disables hardware based VSS snapshots, which will break most storage based snapshot solutions
$ResetRegKey = $True # If set to $True the script will set the value to 1 after the Windows Backup is done

$RegParameters = "HKLM:\Software\Microsoft\ExchangeServer\v14\Replay\Parameters"

$EnableVSSWriter = (Get-ItemProperty $RegParameters).EnableVSSWriter

$Date = Get-Date

If ($EnableVSSWriter -ne 0) {
 Write-Host "Setting EnableVSSWriter=0"
Set-ItemProperty -path $RegParameters -Name "EnableVSSWriter" -value 0 -Type "DWord"
 Write-Host "Restarting the Exchange Replication Service"
Restart-Service "MSExchangeRepl"

ForEach ($Database in $Databases) {
$CurrentDB = Get-MailboxDatabase $Database
$DBDrive = $CurrentDB.EdbFilePath.DriveName
$CurrentServer = $CurrentDB.Server.Name
If ($CurrentServer -ne $Server -and $RequireLocal) {
Write-Host "`nBackup aborted, $Database is active on $CurrentServer, which is not the same as the current server: $Server." -ForegroundColor Yellow
 Else {
Write-Host "Starting backup of database: $Database on drive: $DBDrive" -ForegroundColor Green
If ($DBDrive -eq $Null) {Exit}
$BackupPath = $BackupShare + $Database
$CMDLine = "START BACKUP -backupTarget:" + $BackupPath + " -include:" + $DBDrive +" -vssFull -quiet"
# Write-Host "Running: `n wbadmin.exe $CMDLine "

$pinfo = New-Object System.Diagnostics.ProcessStartInfo
 $pinfo.FileName = "wbadmin.exe"
 $pinfo.RedirectStandardError = $True
 $pinfo.RedirectStandardOutput = $True
 $pinfo.UseShellExecute = $false
 $pinfo.Arguments = $CMDLine
 $Process = New-Object System.Diagnostics.Process
 $Process.StartInfo = $pinfo
 $Process.Start() | Out-Null

$output = $Process.StandardOutput.ReadToEnd()
 "Backup started: $Date" | Out-File "Backup.log" -Append
 $output | Out-File "Backup.log" -Append

$ExitCode = $Process.ExitCode
If ($ExitCode -ne 0) {
Write-Host "`nBackup may have not been successful, ExitCode: $ExitCode was returned`n`n" -ForegroundColor Red
 Write-Host $output
 Else {
Write-Host "Backup of database: $Database finished with no errors" -ForegroundColor Green

If ($ResetRegKey) {
 Write-Host "Setting EnableVSSWriter=1"
Set-ItemProperty -path $RegParameters -Name "EnableVSSWriter" -value 1 -Type "DWord"
 Write-Host "Restarting the Exchange Replication Service"
Restart-Service "MSExchangeRepl"

For more information on this issue, using Windows Backup, and backing up Exchange in general read the following articles.
EHLO Blog: Backup issues and limitations with Exchange 2010 and DAG

TechNet: Using Windows Server Backup to Back Up and Restore Exchange Data

EHLO Blog: Everything You Need to Know About Exchange Backups

NOT the issue, but will come up when trying to search for VSSWriter issue:
KB2616952: Windows Server Backup May fail the Exchange Consistency Check

About jasonsherry

I am a 20 year Exchange consultant and expert. I currently work for Commvault as a Solutions Specialist for Microsoft Infrastructure For more info see my resume at:
This entry was posted in Exchange, Microsoft, Script and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s