Skip to content

Instantly share code, notes, and snippets.

Created November 24, 2017 10:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Rolling forward database restores to find data changes
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment