Repository navigation
Expand file tree
/
Copy pathModule_4_3.ps1
More file actions
50 lines (49 loc) · 2.46 KB
/
Copy pathModule_4_3.ps1
File metadata and controls
50 lines (49 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Write-Host "# MODULE 4 - PROTECT SQL DATABASES
# Scripted Version
## LESSON 3 - RECOVER SQL DATABASES"
Write-Host "Preparing to perform a Centralized Restore"
$RestoreFromHost = "sql-02.demo.local"
$RestoreToHost_Name = "sql-02.demo.local"
$AppServerName = "MSSQLSERVER"
$DataBaseName = "SQLPROD-01"
Write-Host "Read our Restore Host"
$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 6>$null
$RestoreToHost
Write-Host "Read the Asset to restore to identify the Asset Copies"
$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 6>$null
$RestoreAssets = $RestoreAssets | Where-Object name -Match $DataBaseName
Write-Host "Selecting the Asset Copy to Restore"
$RestoreAssets | ft | out-string
### by Filering for a Date Range ...
#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
$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
}
Write-Host "starting the Restore Job:"
$Restore = Restore-PPDMMSSQL_copies @Parameters
$Restore | Get-PPDMRestored_copies
$Restore | Get-PPDMactivities
Write-Host "Waiting for Restore Activity to complete"
do {
Sleep 5
$Activity=$Restore | Get-PPDMactivities
write-host -NoNewline "$($Activity.progress)% "
}
until ($Activity.state -eq "COMPLETED")