Created
November 24, 2017 10:58
-
-
Save Stuart-Moore/c5575e488ff3d95e60403b39b70ca7da to your computer and use it in GitHub Desktop.
Rolling forward database restores to find data changes
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\' | |
$Continue = $true | |
$LoopCount = 0 | |
$NewDbName = 'Creeping' | |
$RestoreResults = @() | |
$Continue = $true | |
While ($Continue -eq $True){ | |
$BackupInfo = Get-DbaBackupInformation -Import -Path c:\temp\bk.xml | |
$BackupInfo = $BackupInfo | Select-DbaBackupInformation -RestoreTime $startDate.AddMinutes($loopCount) | |
$null = $BackupInfo | Format-DbaBackupInformation -DataFileDirectory $BaseDirectory -ReplaceDatabaseName $NewDbName | |
$RestoreResults += $BackupInfo | Invoke-DbaAdvancedRestore -SqlInstance localhost\sqlexpress2016 -StandbyDirectory $BaseDirectory -Continue | |
$results = Invoke-Sqlcmd2 -ServerInstance localhost\sqlexpress2016 -query "select * from steps where step='20'" -Database $NewDbName | |
if ($null -ne $results){ | |
$Continue = $false | |
} | |
$LoopCount++ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment