This will perform a Centralized Restore
$RestoreFromHost = "sqlaag-01.demo.local"
$RestoreToHost_Name = "sqlaag-01.demo.local"
$AppServerName = "AAG-Demo"
$DataBaseName = "DemoDB-01"
$RestoreHostFilter = 'attributes.appHost.applicationsOfInterest.type eq "MSSQL" and not (lastDiscoveryStatus eq "DELETED") and details.appHost.os eq "WINDOWS" and hostname eq "' + $RestoreToHost_Name + '"'
$RestoreToHost = Get-PPDMhosts -filter $RestoreHostFilter
$RestoreToHost
$RestoreAssetFilter = 'type eq "MICROSOFT_SQL_DATABASE" and protectionStatus eq "PROTECTED" and details.database.clusterName eq "' + $RestoreFromHost + '"' + ' and details.database.appServerName eq "' + $AppServerName + '"' + ' and name eq "' + $DataBaseName + '"'
$RestoreAssets = Get-PPDMAssets -Filter $RestoreAssetFilter
# Optionally, look at the CopyMap
# $Copymap=$RestoreAssets | Get-PPDMcopy_map
we have multiple options to select a Copy…..
Get-PPDMlatest_copies -assetID $RestoreAssets.id
write-host "Selecting Asset-copy for $DataBaseName"
$myDate = (get-date).AddDays(-1)
$usedate = get-date $myDate -Format yyyy-MM-ddThh:mm:ssZ
$RANGE_FILTER = 'startTime ge "' + $usedate + '"state eq "IDLE"'
# $RestoreAssets | Get-PPDMassetcopies -filter $RANGE_FILTER
$RestoreAssetCopy = $RestoreAssets | Get-PPDMassetcopies -filter $RANGE_FILTER | Select-Object -First 1
For now, we use the Latest Copy Function
$RestoreAssetCopy = Get-PPDMlatest_copies -assetID $RestoreAssets.id
This time we Specify Parameters in a Parameters Block as this makes it easier to use Options in Scripts
$Parameters = @{
HostID = $RestoreToHost.id
appServerId = $RestoreAssets.details.database.appServerId
copyObject = $RestoreAssetCopy
performTailLogBackup = $true
enableDebug = $false
enableCompressedRestore = $true
fileRelocationOptions = "ORIGINAL_LOCATION"
restoreType = "TO_ALTERNATE"
CustomDescription = "Restore from Powershell"
aagRestoreType = "RESTORE_TO_ALL"
Verbose = $false
}
And finally start the Restore Job:
$Restore = Restore-PPDMMSSQL_copies @Parameters
$Restore | Get-PPDMRestored_copies
$Restore | Get-PPDMactivities
Lets wait until activity Completed:
do { Sleep 5; $Activity=$Restore | Get-PPDMactivities; write-host $Activity.progress } until ($Activity.state -eq "COMPLETED")
«Module 4 Lesson 1 This Concludes Module 4 Lesson 2 Module 5 Lesson 1»