This will perform a Centralized Restore
$RestoreFromHost = "sql-02.demo.local"
$RestoreToHost_Name = "sql-02.demo.local"
$AppServerName = "MSSQLSERVER"
$DataBaseName = "SQLPROD-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 + '"'
$RestoreAssets = Get-PPDMAssets -Filter $RestoreAssetFilter
$RestoreAssets = $RestoreAssets | Where-Object name -Match $DataBaseName
# 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
enableDebug = $false
enableCompressedRestore = $true
fileRelocationOptions = "ORIGINAL_LOCATION"
restoreType = "TO_ALTERNATE"
CustomDescription = "Restore from Powershell"
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 2 This Concludes Module 4 Lesson 3 Module 4 Lesson 4»