Testing Backup-DbaDatabase - Restore model after the all-databases backup test - #10582
Open
andreasjordan wants to merge 1 commit into
Open
Testing Backup-DbaDatabase - Restore model after the all-databases backup test#10582andreasjordan wants to merge 1 commit into
andreasjordan wants to merge 1 commit into
Conversation
The context "Properly backups all databases" backs up every database of InstanceCopy1, so it also takes a full backup of model. As model is in the full recovery model, that backup starts its log chain, and because no log backup ever follows, the log can never be reused and grows on every run of this file. The growth is in the file size, so a restart does not undo it, and once the log passes 32 MB it breaks New-DbaDatabase.Tests.ps1, which asserts the exact log size of a new database on the same instance. The new AfterAll records the recovery model and log size before the backup and restores both afterwards. Switching to the simple recovery model is what makes the log reusable again - without it the shrink cannot release anything and the file even grows instead. Also removes a TODO that is answered: 06_configure_instances.ps1 creates the master key on every lab instance at startup. (do Backup-DbaDatabase) Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The context "Properly backups all databases" backs up every database of
InstanceCopy1, so it also takes a full backup ofmodel. Asmodelis in the full recovery model, that backup starts its log chain, and because no log backup ever follows, the log can never be reused and grows a little on every run of this file.That growth is in the file size, so a restart does not undo it. It surfaces much later as a completely unrelated failure: a new database's log is never smaller than
model's, soNew-DbaDatabase.Tests.ps1fails its log size assertion oncemodel's log passes 32 MB. In our labmodelhad reached 72 MB and the failure looked like this, on an instance where the other assertions of the same test passed:InstanceCopy1andInstanceMulti2are the same instance in our configuration, which is why this file damages that one.The fix
The context's
BeforeAllnow recordsmodel's recovery model and log size before the backup, and a newAfterAllrestores both.Switching to the simple recovery model is what makes the log reusable again. Without it the shrink cannot release anything, because the log still waits for a log backup, and the file even grows instead - a plain
DBCC SHRINKFILEtook ourmodellog from 72 MB to 136 MB.DBCC SHRINKFILEalso resolves the logical file name in the current database, so it has to run inmodelwhile the twoALTER DATABASEstatements run frommaster.The original recovery model is restored rather than a hardcoded
FULL, and the whole block is skipped whenmodelis already in the simple recovery model, so there is nothing to break.This also removes a
TODOthat is answered: the master key it asks about is created on every lab instance at startup.Verification
Backup-DbaDatabase.Tests.ps1passes unchanged: 48 passed, 2 skipped, 0 failed, the same counts as before.modelis left exactly as found: full recovery model,log_reuse_wait_descNOTHING, log at its original 8 MB, andlast_log_backup_lsnback toNULL, so the chain is really closed and not just the file shrunk.New-DbaDatabase.Tests.ps1passes 13/13 again oncemodelis repaired.This text was created by Claude and reviewed by Andreas Jordan.
馃 Generated with Claude Code