# ==============================================================================================
#
# Microsoft PowerShell Source File -- Created with SAPIEN Technologies PrimalScript 2009
#
# NAME: Export SCDPM 2007 Exchange Recovery Points on a Schedule
#
# VERSION: 1.0
#
# AUTHOR: Pete Zerger (www.systemcentercentral.com) and UNKNOWN (I based this on a SQL monitoring snippet I found in a newsgroup)
#
# DESCRIPTION: This Script will Restore the latest recovery point for all Exchange storage groups
#              within specified protection group to a network folder. This script is intended to
#              run as a scheduled task to dump these recovery points to disk. This allows another
#              backup systems can back the data up to tape.
#
#              This script exports recovery points to disks serially (one at a time), but can be
#              modified to dump all in parallel (see commented sectoin at the end of this script).
# ==============================================================================================

#Load DPM cmdlets so we can run from a standard Powershell prompt
Add-PSSnapin Microsoft.DataProtectionManager.PowerShell

# ==================
#Variables
# ==================

#Protection group name or wildcard (allows for alternate restore of multiple protection groups at once)
$pgName = "My_Exchange_Protection_Group"

#DPM server name, destination server and local restore path
$DPMServerName = "MyDPMServer"
$DestinationServerName = "MyDESTServer"
$DestinationLocation = "D:\Daily\EXCHANGE\"

#Resource type being protected.
$objtype = "Storage group"

# ==========================
# End of variable definition
# ==========================

# write-host "This Script will Restore the latest recovery point for all Exchange storage groups within specified protection group to a network folder"

if (!(Connect-DPMServer $DPMServerName))
{
Write-Error "Failed to connect To DPM server $DPMServerName"
exit 1
}

#Get the protection group for variable $PgName

$pg = Get-ProtectionGroup $DPMServerName | where { $_.FriendlyName -like $pgName }

if(!$pg)
{
Write-Host "Protection group " $pgName " not found"
exit 1
}

#Get a list of all Datasources with a type of "$ObjType"

$ds = Get-Datasource $pg #|

if(!$ds)
{
Write-Host "error"
exit 1
}

# =========================================================
#BEGIN DEBUG CODE: Writes datasource and type to the screen
# =========================================================

#foreach ($datasource in $ds)
#{
#Write-Host $datasource.type.name " : " $datasource.name
#}
#if (!$Objtype)
#{
# $Objtype = Read-Host "Object type ie : SQL Server 2005 database : "

#if (!$DestinationLocation)
#{
# Write-Error "Object type not specified"
# exit 1
# }
#}

#Display a list of "SqlObjects"

# Restore the latest recovery point of each SQL datasource.
foreach ($datasource in $ds)
{
if ($datasource.type.name -eq $objtype)
{
    Write-Host $datasource.name
    Write-Host $datasource.type.name

# Restore the latest recovery point of each SQL datasource.

# Select the latest recovery point that exists on disk and trigger the restore job.
foreach ($rp in @(Get-RecoveryPoint -Datasource $datasource | sort -Property RepresentedPointInTime -Descending))
{
foreach ($rsl in $rp.RecoverySourceLocations)
{
if ($rsl -is [Microsoft.Internal.EnterpriseStorage.Dls.UI.ObjectModel.OMCommon.ReplicaDataset])
{
$recoveryOption = New-RecoveryOption -TargetServer $DestinationServerName -TargetLocation $DestinationLocation -RecoveryLocation CopyToFolder -Exchange -ExchangeOperationType NoOperation -RecoveryType Restore

$restoreJob = Recover-RecoverableItem -RecoverableItem $rp -RecoveryOption $recoveryOption -RecoveryPointLocation $rsl

break
}
}

if ($restoreJob)
{
break
}
}

if ($restoreJob)
{
Write-Host "`nRunning restore of $($datasource.LogicalPath) from
$($rp.RepresentedPointInTime) to $DestinationServerName\$DestinationLocation"
# Comment out the next 7 lines to not wait for one restore job to finish before triggering the next one.
while (!$restoreJob.HasCompleted)
{
Write-Host "." -NoNewLine
sleep 3
}

Write-Host "`nJob status: $($restoreJob.Status)"
}
else
{
Write-Error "Could not find a recovery point on disk for
$($datasource.LogicalPath)"
}

}

}



pzerger  ...
Click here to play