-
-
Save Stuart-Moore/00cbc4c3cf31583cae99c36f0494bf94 to your computer and use it in GitHub Desktop.
Restore db to different point in times
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
Get-DbaBackupInformation -sqlinstance localhost\sqlexpress2016 -Path C:\dbatools\RestoreTimeDiffDemo -ExportPath C:\temp\bk.xml | |
$BackupSelection = New-Object System.Collections.ArrayList | |
$startDate = Get-Date '24/11/2017 09:22' | |
$BaseDirectory = 'c:\restores\' | |
for ($i=0; $i -lt 35; $i+=7){ | |
$BackupInfo = Get-DbaBackupInformation -Import -Path c:\temp\bk.xml | |
$BackupInfo = $BackupInfo | Select-DbaBackupInformation -RestoreTime $startDate.AddMinutes($i) | |
$DbName = $BackupInfo[0].Database | |
$RestorePath = ([io.path]::Combine($BaseDirectory,$DbName,$startDate.AddMinutes($i).ToString('hhmmddMMyyyy'))) | |
$NewDbName = $DbName+"_"+$startDate.AddMinutes($i).ToString('hhmmddMMyyyy') | |
$null = $BackupInfo | Format-DbaBackupInformation -DataFileDirectory $RestorePath -ReplaceDatabaseName $NewDbName | |
$BackupSelection.Add($BackupInfo) > null | |
} | |
$null = $BackupSelection | Test-DbaBackupInformation -SqlInstance localhost\sqlexpress2016 -Withreplace | |
$RestoreOutput = $BackupSelection | Invoke-DbaAdvancedRestore -SqlInstance localhost\sqlexpress2016 -WithReplace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment