-
-
Notifications
You must be signed in to change notification settings - Fork 785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restore-DbaDatabase - Changed WhatIf message / added deep copy of FileList #7410
Conversation
Not sure if the deep copy has some side effects. Will have to look at that. |
Ok, deep copy breaks Test-DbaLastBackup, more work has to be done... |
Hey @Stuart-Moore, can you please review this PR? 🙏🏼 |
Will reach out to Stuart on Twitter, this command is ultra important so I want to ensure he gets a look. |
Does the copy not want to be a bit further into the function? All the ways of passing the backup info into the function end up in BackupHistory objects, so should all be affected? Somewhere like line 619 in your modified file Not played with this for a long time and have been rotting my brain with ADF and Dynamics so may have missed something. The overall way of doing it should work. would be nice to see a test adding, just to make sure someone else doesn't break it later on by mistake or by misunderstanding. |
Hi @Stuart-Moore , I had another look at this and found a better solution. I realized that you do a lot of |
@@ -677,7 +679,7 @@ function Restore-DbaDatabase { | |||
return | |||
} | |||
$pathSep = Get-DbaPathSep -Server $RestoreInstance | |||
$null = $BackupHistory | Format-DbaBackupInformation -DataFileDirectory $DestinationDataDirectory -LogFileDirectory $DestinationLogDirectory -DestinationFileStreamDirectory $DestinationFileStreamDirectory -DatabaseFileSuffix $DestinationFileSuffix -DatabaseFilePrefix $DestinationFilePrefix -DatabaseNamePrefix $RestoredDatabaseNamePrefix -ReplaceDatabaseName $DatabaseName -Continue:$Continue -ReplaceDbNameInFile:$ReplaceDbNameInFile -FileMapping $FileMapping -PathSep $pathSep | |||
$BackupHistory = $BackupHistory | Format-DbaBackupInformation -DataFileDirectory $DestinationDataDirectory -LogFileDirectory $DestinationLogDirectory -DestinationFileStreamDirectory $DestinationFileStreamDirectory -DatabaseFileSuffix $DestinationFileSuffix -DatabaseFilePrefix $DestinationFilePrefix -DatabaseNamePrefix $RestoredDatabaseNamePrefix -ReplaceDatabaseName $DatabaseName -Continue:$Continue -ReplaceDbNameInFile:$ReplaceDbNameInFile -FileMapping $FileMapping -PathSep $pathSep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
$BackupHistory += $F | Select-Object *, @{ Name = "ServerName"; Expression = { $_.SqlInstance } }, @{ Name = "BackupStartDate"; Expression = { $_.Start -as [DateTime] } } | ||
# Fix #5036 by implementing a deep copy of the FileList | ||
$f.FileList = $f.FileList | Select-Object * | ||
$BackupHistory += $f | Select-Object *, @{ Name = "ServerName"; Expression = { $_.SqlInstance } }, @{ Name = "BackupStartDate"; Expression = { $_.Start -as [DateTime] } } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should do it.
@@ -143,6 +143,16 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { | |||
} | |||
} | |||
|
|||
Context "Replace databasename in Restored File, but don't change backup history #5036" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests are good 👍
Should stop your hard work getting broken further on down the line
Happy with all of that. Merging in the new changes from dev to make sure all is still good, then i'll merge it in properly. If I get distracted, anyone else who wants to merge it, please do. |
Squashed and merged Nice work @andreasjordan |
Thank you all! 🙇🏼 I'll release this hopefully within the next 48 hours. I'm working on an auto releaser and happy to have something in the queue. |
Type of Change