Created
April 30, 2019 00:03
-
-
Save nanoDBA/b7789873b6fbd3b49596b659a80a840c to your computer and use it in GitHub Desktop.
Demo - PowerShell + DevOps Global Summit 2019 - Parallel Restores
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Restoring Databases from Files in Parallel | |
# Let's restore 11, 21, 41 databases! | |
$DbSuffixRange = 500..510 | |
# $DbSuffixRange = 500..520 | |
# $DbSuffixRange = 500..540 | |
$RSJobparamHash = @{ | |
Throttle = 8 | |
ModulesToImport = "dbatools" | |
InputObject = $DbSuffixRange | |
Verbose = $True | |
} | |
Start-RSJob @RSJobparamHash -ScriptBlock { | |
# How will the backup headers be scanned? SQL Server and Backup Path | |
$BkParamHash = @{ | |
SqlInstance = "localhost" | |
Path = "D:\Share01\Demo", "D:\Share02\Demo" | |
} | |
$BackupMetaData = Get-DbaBackupInformation @BkParamHash -Verbose | |
$DbSuffix = $_ | |
#$DbSuffix = [string]$DbSuffix | |
Write-Output "$DbSuffix ***" | Out-String | Write-Host -ForegroundColor Cyan | |
$FileMapping = @{ | |
'pubs' = "C:\SQLDataFiles\pubs_$DbSuffix.mdf" | |
'pubs_Log' = "C:\SQLLogFiles\pubs_log$DbSuffix.ldf" | |
} | |
$RestoreParamHash = @{ | |
sqlinstance = "localhost" | |
DatabaseName = "pubs_$DbSuffix" | |
FileMapping = $FileMapping | |
#TrustDbBackupHistory = $True | |
} | |
$BackupMetaData | Restore-DbaDatabase @RestoreparamHash -Verbose ` | |
| Wait-RSJob -ShowProgress -Verbose | Receive-RSJob -Verbose; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment