Skip to content

Commit 594dd6a

Browse files
Install-DbaMaintenanceSolution - Fix NUL backup validation for stored-proc installs (review of #10247)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent cc136ba commit 594dd6a

3 files changed

Lines changed: 40 additions & 3 deletions

File tree

docs/trackers/features/commit-bug-review-TRACKER.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Find real bugs (logic errors, null refs, incorrect behavior) and fix them. Skip
9797
| 50c0bfdaf | Connect-DbaInstance - Add -AuthenticationType parameter for Entra ID support (#10271) | DONE | Fixed password-based AuthenticationType handling so explicit Entra auth uses SqlConnectionInfo credentials, added missing SqlCredential validation, and added unit regression tests. |
9898
| 27e4da9d1 | Get-DbaDbOrphanUser - Skip SQL login orphan check for contained databases (#10270) | DONE | Guarded ContainmentType for pre-SQL 2012 servers and added unit regression tests. |
9999
| 21a522047 | Test-DbaAgPolicyState - Add new command for Always On policy state checks (#10246) | DONE | Added missing replica sync policy, corrected Microsoft category/name mismatches, and added regression tests. |
100-
| 1f43cbbf0 | Install-DbaMaintenanceSolution: change Compress/Verify/CheckSum to ValidateSet string params (#10247) | PENDING | |
100+
| 1f43cbbf0 | Install-DbaMaintenanceSolution: change Compress/Verify/CheckSum to ValidateSet string params (#10247) | DONE | Scoped NUL/Verify validation to InstallJobs, added a unit regression test, and corrected the AutoScheduleJobs example. |
101101
| 444659b0a | Get-DbaDbMailAccount, Get-DbaDbMailProfile - Add Account-Profile link details (#10280) | PENDING | |
102102
| 57fa89a0e | Invoke-DbaDbShrink - Add error message output for failed shrink operations (#10258) | PENDING | |
103103
| df60d986f | Export-DbaUser - Add schema ownership to exported scripts (#10275) | PENDING | |

public/Install-DbaMaintenanceSolution.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ function Install-DbaMaintenanceSolution {
223223
>> SqlInstance = "localhost"
224224
>> InstallJobs = $true
225225
>> CleanupTime = 720
226-
>> AutoSchedule = "WeeklyFull"
226+
>> AutoScheduleJobs = "WeeklyFull"
227227
>> }
228228
>> Install-DbaMaintenanceSolution @params
229229
@@ -324,7 +324,7 @@ function Install-DbaMaintenanceSolution {
324324
return
325325
}
326326

327-
if ($BackupLocation -eq "NUL" -and $Verify -notin "ForceOff", "Remove") {
327+
if ($InstallJobs -and $BackupLocation -eq "NUL" -and $Verify -notin "ForceOff", "Remove") {
328328
Stop-Function -Message "Verify is not supported when backing up to NUL. Either backup to a different directory or set -Verify to 'ForceOff' or 'Remove'."
329329
return
330330
}

tests/Install-DbaMaintenanceSolution.Tests.ps1

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,43 @@ Describe $CommandName -Tag UnitTests {
3737
Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $hasParameters | Should -BeNullOrEmpty
3838
}
3939
}
40+
41+
InModuleScope dbatools {
42+
Context "BackupLocation validation" {
43+
BeforeEach {
44+
Mock Stop-Function { throw $Message }
45+
Mock Connect-DbaInstance { throw "connect failed" }
46+
Mock Get-DbatoolsConfigValue { "C:\temp" }
47+
Mock Join-DbaPath { "C:\temp" }
48+
Mock Test-Path { $true }
49+
Mock Save-DbaCommunitySoftware { throw "should not download" }
50+
}
51+
52+
It "Allows NUL backup locations when jobs are not being installed" {
53+
{
54+
Install-DbaMaintenanceSolution -SqlInstance "sql1" -BackupLocation "NUL"
55+
} | Should -Throw "*Error occurred while establishing connection to sql1*"
56+
57+
Should -Invoke Connect-DbaInstance -Times 1 -Exactly
58+
Should -Invoke Save-DbaCommunitySoftware -Times 0 -Exactly
59+
Should -Invoke Stop-Function -Times 0 -Exactly -ParameterFilter {
60+
$Message -like "Verify is not supported when backing up to NUL*"
61+
}
62+
}
63+
64+
It "Blocks NUL backup locations when default job verification would still be enabled" {
65+
{
66+
Install-DbaMaintenanceSolution -SqlInstance "sql1" -BackupLocation "NUL" -InstallJobs
67+
} | Should -Throw "*Verify is not supported when backing up to NUL*"
68+
69+
Should -Invoke Connect-DbaInstance -Times 0 -Exactly
70+
Should -Invoke Save-DbaCommunitySoftware -Times 0 -Exactly
71+
Should -Invoke Stop-Function -Times 1 -Exactly -ParameterFilter {
72+
$Message -like "Verify is not supported when backing up to NUL*"
73+
}
74+
}
75+
}
76+
}
4077
}
4178

4279
Describe $CommandName -Tag IntegrationTests {

0 commit comments

Comments
 (0)