Skip to content

Instantly share code, notes, and snippets.

@nanoDBA
Created April 30, 2019 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nanoDBA/1e0f338f9c6571efd471fe49128d2800 to your computer and use it in GitHub Desktop.
Save nanoDBA/1e0f338f9c6571efd471fe49128d2800 to your computer and use it in GitHub Desktop.
Demo - PowerShell + DevOps Global Summit 2019 - Sequential Restores
# 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
# Let's restore 11 databases
$DbSuffixRange = 500..510
ForEach ($DbSuffix in $DbSuffixRange) {
#$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
}
<#
-FileMapping <Hashtable>
A hashtable that can be used to move specific files to a location.
$FileMapping = @{'DataFile1'='c:\restoredfiles\Datafile1.mdf';'DataFile3'='d:\DataFile3.mdf'}
And files not specified in the mapping will be restored to their original location
This Parameter is exclusive with DestinationDataDirectory
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment