# ********************************************************************************************* # Prepare Windows Server 2008 Backup With (or without) Exchange Plug-in for # Exchange 2007 # Version 1.0 # Author: Andy Grogan # http://www.telnetport25.com # # # ********************************************************************************************* function Select-TSSYSFolder($TitleCap, $path = 0) { $object = New-Object -comObject Shell.Application $folder = $object.BrowseForFolder(0, $TitleCap, 0, $path) if ($folder -ne $null) { $folder.self.Path } } function Select-EDBFileDialog { param([string]$Title,[string]$Directory,[string]$Filter="Exchange Database Files (*.edb)|*.edb") [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null $objForm = New-Object System.Windows.Forms.OpenFileDialog $objForm.InitialDirectory = $Directory $objForm.Filter = $Filter $objForm.Title = $Title $objForm.ShowHelp = $true $Show = $objForm.ShowDialog() If ($Show -eq "OK") { Return $objForm.FileName } Else { Exit } } function SAVE-EDBFileDialog { param([string]$Title,[string]$Directory,[string]$Filter="Exchange Database Files (*.edb)|*.edb") [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null $objForm = New-Object System.Windows.Forms.SaveFileDialog $objForm.InitialDirectory = $Directory $objForm.Filter = $Filter $objForm.Title = $Title $objForm.ShowHelp = $true $Show = $objForm.ShowDialog() If ($Show -eq "OK") { Return $objForm.FileName } Else { Exit } } function CreateRSG($strServer,$cpyLogs,$cpyEDB){ Write-Host "" Write-Host "We are about to create the RSG and assign a database to it" -ForegroundColor Yellow Write-Host "" $mbxDBs = Get-MailboxDatabase -Server $strServer $dbCount = 0 $strLog = Select-TSSYSFolder "Choose a local path for the RSG Transaction Logs" $strSys = Select-TSSYSFolder "Choose a local path for the RSG System Path" Write-Host "" $strRSGName = Read-Host "Please provide a Name for the RSG" Write-Host "Please choose a location for the RSG Database (please enclude the EDB filename)" $strEDBName = SAVE-EDBFileDialog Write-Host "" Write-Host "--------------------------------------------------------------------------------" -BackgroundColor Blue Write-Host "The following databases have been found on your selected server - please choose one to assign to the RSG" Write-Host "" If ($mbxDBs.count -eq $null){ Write-Host "" $DBchc = Read-Host "Please choose the database to add to the RSG from above" Write-Host "" new-storagegroup -Server $strServer -LogFolderPath $strLog -Name $strRSGName -SystemFolderPath $strSys -Recovery new-mailboxdatabase -mailboxdatabasetorecover $mbxDbs -storagegroup $strServer\$strRSGName -EDBFilePath $strEDBName Write-Host "" }else{ Foreach ($mbxDB in $mbxDBs){ Write-Host $dbCount". -"$mbxDB $dbCount ++ } Write-Host "" $DBchc = Read-Host "Please choose the database to add to the RSG from above (This should match the restored database files)" Write-Host "" new-storagegroup -Server $strServer -LogFolderPath $strLog -Name $strRSGName -SystemFolderPath $strSys -Recovery new-mailboxdatabase -mailboxdatabasetorecover $mbxDbs[$DBchc] -storagegroup $strServer\$strRSGName -EDBFilePath $strEDBName Write-Host "--------------------------------------------------------------------------------" -BackgroundColor Blue Write-Host "" } } function CopyItemsFromRecoveryToRSG($SourceLogs,$SourceEDB,$DestLogs,$destEDB){ Write-Host "" Write-Host "Copying the Files from the Backup to the RSG Locations" -BackgroundColor Red Write-Host "" Copy-Item $SourceLogs\* $DestLogs\ -Recurse Copy-Item $SourceEDB\* $DestEDB\ -Recurse Write-Host "" } function FixRestoredDB(){ Write-Host "" Write-Host "We are about to configure the restored Windows Server Backup Database for use with an RSG" -ForegroundColor Yellow Write-Host "" $LogSuffix = Read-Host "Please enter in the prefix of the Restored Transaction log range - (e.g. E00)" $LogFiles = Select-TSSYSFolder "Please choose the location of the RESTORED Transaction Logs:" $SysPath = Select-TSSYSFolder "Please choose the location of the RESTORED SysPath:" $Database = Select-EDBFileDialog "Please choose the location of the restored EDB:" Write-Host "--------------------------------------------------------------------------------" -BackgroundColor Blue Write-Host " *** - Log File Location: " $LogFiles Write-Host " *** - System Path Location: " $SysPath Write-Host " *** - Selected Database: " $Database Write-Host "--------------------------------------------------------------------------------" -BackgroundColor Blue Write-Host "" eseutil.exe /R $LogSuffix /s$SysPath\ /l$LogFiles\ /d$Database /i eseutil.exe /MH $Database Write-Host "" Write-Host "Please verify the above report - please ensure that the database has a Status of: Clean Shutdown" -ForegroundColor Cyan Write-Host "" $GoodToGo = Read-Host "Does the restored Database Show as a clean Shutdown (Y or N)?" If ($GoodToGo.ToLower() -eq "n"){ Write-Host "" Write-Warning "This option will force your Database to Mount under the RSG - some data might be lost" eseutil.exe /P $Database Write-Host "" } } Write-Host "-------------------------------------------------------------" Write-Host "* Windows 2008 Server Backup with Exchange Plug-in" Write-Host "* Recovery Storage Group Script" Write-Host "* Version 1.0" Write-Host "* Author: Andy Grogan - http://www.telnetport25.com" Write-Host "* " Write-Host "* Features: Restore DB Backup from Windows 2008 Back-up" Write-Host "* Patch the database for the RSG" Write-Host "* Copy the files to a RSG" Write-Host "-------------------------------------------------------------" Write-Host "" FixRestoredDB $MailboxSvr = Get-ExchangeServer | Where {$_.adminDisplayVersion -like '*8*' -and $_.isMailboxServer -eq 'True'} $Count = 0 If ($MailboxSvr.Count -eq $Null){ # If there is only one mailbox server do the following code CreateRSG $MailboxSvr $sourceLog = Select-TSSYSFolder "Please choose the Source TS Logs Location to Copy to the RSG:" $destLog = Select-TSSYSFolder "Please choose the Destination Logs Location IN the RSG:" $sourceDB = Select-TSSYSFolder "Please choose the Source DB Location to copy to the RSG:" $DestDB = Select-TSSYSFolder "Please choose the Destination DB Location IN the RSG:" CopyItemsFromRecoveryToRSG $sourceLog $sourceDB $destLog $DestDB Write-Host "The script has now completed!" -ForegroundColor White }else{ Write-Host "--------------------------------------------------------------------------------" -BackgroundColor Blue Write-Host " The following Mailbox Servers have been found" Write-Host"" Foreach ($mbxSrv in $MailboxSvr){ Write-Host $Count". - "$mbxSrv $Count ++ } Write-Host "" Write-Host "--------------------------------------------------------------------------------" -BackgroundColor Blue Write-Host"" $Choice = Read-Host "Please choose the number which matches the name of the mailbox Server from above on which you wish to create the RSG" CreateRSG $MailboxSvr[$Choice] $sourceLog = Select-TSSYSFolder "Please choose the Source TS Logs Location to Copy to the RSG:" $destLog = Select-TSSYSFolder "Please choose the Destination Logs Location IN the RSG:" $sourceDB = Select-TSSYSFolder "Please choose the Source DB Location to copy to the RSG:" $DestDB = Select-TSSYSFolder "Please choose the Destination DB Location IN the RSG:" CopyItemsFromRecoveryToRSG $sourceLog $sourceDB $destLog $DestDB Write-Host "The script has now completed!" -ForegroundColor White }