Skip to content

Commit 4ee6b23

Browse files
Install-DbaMaintenanceSolution: change Compress/Verify/CheckSum to ValidateSet string params
Fixes #10183. The -Compress, -Verify and -CheckSum parameters were switches, which caused documentation/behaviour mismatches: - Switch default ($false) would set @compress = 'N' even when not specified - Switch default ($false) would override Ola's @verify = 'Y' default Changed all three to [string] with [ValidateSet('Default', 'ForceOn', 'ForceOff', 'Remove')]: - Default: leaves job text unchanged (Ola's defaults: Verify='Y', Checksum='Y', no Compress) - ForceOn: explicitly sets parameter to 'Y' - ForceOff: explicitly sets parameter to 'N' - Remove: strips the parameter from job text entirely Updated NUL+Verify validation to check for ForceOff/Remove instead of boolean false. Updated all integration tests to use the new string values. (do *MaintenanceSolution*) Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
1 parent aa4e253 commit 4ee6b23

2 files changed

Lines changed: 84 additions & 50 deletions

File tree

public/Install-DbaMaintenanceSolution.ps1

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,11 @@ function Install-DbaMaintenanceSolution {
8282
This ensures backup chains remain valid even if scheduled full backups fail or are missed.
8383
8484
.PARAMETER Compress
85-
Controls backup compression for all backup operations. When not specified, uses the SQL Server instance's default compression setting.
86-
Set to enable compression (recommended for reducing backup size and network transfer time) or disable for compatibility with older restore targets.
85+
Controls backup compression in job commands. Valid values: Default, ForceOn, ForceOff, Remove.
86+
Default: does not include @Compress in job text, so the SQL Server instance's compression setting applies.
87+
ForceOn: explicitly sets @Compress = 'Y' in job commands.
88+
ForceOff: explicitly sets @Compress = 'N' in job commands.
89+
Remove: removes @Compress from job commands if present.
8790
Only applies when InstallJobs is specified.
8891
8992
.PARAMETER CopyOnly
@@ -92,13 +95,19 @@ function Install-DbaMaintenanceSolution {
9295
Only applies when InstallJobs is specified.
9396
9497
.PARAMETER Verify
95-
Verifies backup integrity immediately after creation by performing a RESTORE VERIFYONLY operation.
96-
Defaults to enabled (Y) if not specified. Verification adds time to backup operations but ensures backups are restorable.
98+
Controls backup verification in job commands. Valid values: Default, ForceOn, ForceOff, Remove.
99+
Default: uses Ola's default, which includes @Verify = 'Y' in job commands.
100+
ForceOn: explicitly sets @Verify = 'Y' in job commands.
101+
ForceOff: explicitly sets @Verify = 'N' in job commands.
102+
Remove: removes @Verify from job commands, letting the stored procedure's built-in default apply.
97103
Only applies when InstallJobs is specified.
98104
99105
.PARAMETER CheckSum
100-
Enables checksum validation during backup operations to detect data corruption.
101-
Defaults to enabled (Y) if not specified. Checksums provide additional data integrity verification with minimal performance impact.
106+
Controls checksum validation in job commands. Valid values: Default, ForceOn, ForceOff, Remove.
107+
Default: uses Ola's default, which includes @Checksum = 'Y' in job commands.
108+
ForceOn: explicitly sets @CheckSum = 'Y' in job commands.
109+
ForceOff: explicitly sets @CheckSum = 'N' in job commands.
110+
Remove: removes @CheckSum from job commands, letting the stored procedure's built-in default apply.
102111
Only applies when InstallJobs is specified.
103112
104113
.PARAMETER ModificationLevel
@@ -257,9 +266,9 @@ function Install-DbaMaintenanceSolution {
257266
>> BackupLocation = "D:\SQLBackups"
258267
>> CleanupTime = 168
259268
>> ChangeBackupType = $true
260-
>> Compress = $true
261-
>> Verify = $true
262-
>> CheckSum = $true
269+
>> Compress = "ForceOn"
270+
>> Verify = "ForceOn"
271+
>> CheckSum = "ForceOn"
263272
>> }
264273
265274
PS C:\> Install-DbaMaintenanceSolution @params
@@ -291,10 +300,13 @@ function Install-DbaMaintenanceSolution {
291300
[switch]$Force,
292301
[switch]$InstallParallel,
293302
[switch]$ChangeBackupType,
294-
[switch]$Compress,
303+
[ValidateSet('Default', 'ForceOn', 'ForceOff', 'Remove')]
304+
[string]$Compress = "Default",
295305
[switch]$CopyOnly,
296-
[switch]$Verify,
297-
[switch]$CheckSum,
306+
[ValidateSet('Default', 'ForceOn', 'ForceOff', 'Remove')]
307+
[string]$Verify = "Default",
308+
[ValidateSet('Default', 'ForceOn', 'ForceOff', 'Remove')]
309+
[string]$CheckSum = "Default",
298310
[ValidateRange(0, 100)]
299311
[int]$ModificationLevel,
300312
[switch]$EnableException
@@ -312,8 +324,8 @@ function Install-DbaMaintenanceSolution {
312324
return
313325
}
314326

315-
if ($BackupLocation -eq "NUL" -and $Verify) {
316-
Stop-Function -Message "Verify is not supported when backing up to NUL. Either backup to a different directory or turn off Verify."
327+
if ($BackupLocation -eq "NUL" -and $Verify -notin "ForceOff", "Remove") {
328+
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'."
317329
return
318330
}
319331

@@ -767,17 +779,21 @@ function Install-DbaMaintenanceSolution {
767779
}
768780
}
769781

770-
# Add Compress parameter for all backup jobs
771-
if ($Compress) {
782+
# Compress parameter for all backup jobs
783+
# Default: do not include @Compress (instance-level setting applies)
784+
if ($Compress -eq "ForceOn") {
772785
$modifiedCommand = $modifiedCommand -replace "@Compress = 'N'", "@Compress = 'Y'"
773786
if ($modifiedCommand -notmatch "@Compress") {
774787
$modifiedCommand = $modifiedCommand -replace "(@LogToTable = '[YN]')", "`$1,$([System.Environment]::NewLine)@Compress = 'Y'"
775788
}
776-
} else {
789+
} elseif ($Compress -eq "ForceOff") {
777790
$modifiedCommand = $modifiedCommand -replace "@Compress = 'Y'", "@Compress = 'N'"
778791
if ($modifiedCommand -notmatch "@Compress") {
779792
$modifiedCommand = $modifiedCommand -replace "(@LogToTable = '[YN]')", "`$1,$([System.Environment]::NewLine)@Compress = 'N'"
780-
}
793+
}
794+
} elseif ($Compress -eq "Remove") {
795+
$modifiedCommand = $modifiedCommand -replace "@Compress = '[YN]',\r?\n", ""
796+
$modifiedCommand = $modifiedCommand -replace ",\r?\n@Compress = '[YN]'", ""
781797
}
782798

783799
# Add CopyOnly parameter for all backup jobs
@@ -787,20 +803,38 @@ function Install-DbaMaintenanceSolution {
787803
}
788804
}
789805

790-
# Add Verify parameter for all backup jobs
791-
# Ola turns this on by default, so all we have to do is turn it off if asked.
792-
if (-not $Verify) {
793-
if ($modifiedCommand -notmatch "@Verify = 'N'") {
794-
$modifiedCommand = $modifiedCommand -replace "@Verify = 'Y'", "@Verify = 'N'"
806+
# Verify parameter for all backup jobs
807+
# Ola includes @Verify = 'Y' by default. Default: leave unchanged.
808+
if ($Verify -eq "ForceOn") {
809+
$modifiedCommand = $modifiedCommand -replace "@Verify = 'N'", "@Verify = 'Y'"
810+
if ($modifiedCommand -notmatch "@Verify") {
811+
$modifiedCommand = $modifiedCommand -replace "(@LogToTable = '[YN]')", "`$1,$([System.Environment]::NewLine)@Verify = 'Y'"
812+
}
813+
} elseif ($Verify -eq "ForceOff") {
814+
$modifiedCommand = $modifiedCommand -replace "@Verify = 'Y'", "@Verify = 'N'"
815+
if ($modifiedCommand -notmatch "@Verify") {
816+
$modifiedCommand = $modifiedCommand -replace "(@LogToTable = '[YN]')", "`$1,$([System.Environment]::NewLine)@Verify = 'N'"
795817
}
818+
} elseif ($Verify -eq "Remove") {
819+
$modifiedCommand = $modifiedCommand -replace "@Verify = '[YN]',\r?\n", ""
820+
$modifiedCommand = $modifiedCommand -replace ",\r?\n@Verify = '[YN]'", ""
796821
}
797822

798-
# Add CheckSum parameter for all backup jobs
799-
# Ola turns this on by default, so all we have to do is turn it off if asked.
800-
if (-not $CheckSum) {
801-
if ($modifiedCommand -notmatch "@CheckSum = 'N'") {
802-
$modifiedCommand = $modifiedCommand -replace "@CheckSum = 'Y'", "@CheckSum = 'N'"
823+
# CheckSum parameter for all backup jobs
824+
# Ola includes @Checksum = 'Y' by default. Default: leave unchanged.
825+
if ($CheckSum -eq "ForceOn") {
826+
$modifiedCommand = $modifiedCommand -replace "@CheckSum = 'N'", "@CheckSum = 'Y'"
827+
if ($modifiedCommand -notmatch "@CheckSum") {
828+
$modifiedCommand = $modifiedCommand -replace "(@LogToTable = '[YN]')", "`$1,$([System.Environment]::NewLine)@CheckSum = 'Y'"
829+
}
830+
} elseif ($CheckSum -eq "ForceOff") {
831+
$modifiedCommand = $modifiedCommand -replace "@CheckSum = 'Y'", "@CheckSum = 'N'"
832+
if ($modifiedCommand -notmatch "@CheckSum") {
833+
$modifiedCommand = $modifiedCommand -replace "(@LogToTable = '[YN]')", "`$1,$([System.Environment]::NewLine)@CheckSum = 'N'"
803834
}
835+
} elseif ($CheckSum -eq "Remove") {
836+
$modifiedCommand = $modifiedCommand -replace "@CheckSum = '[YN]',\r?\n", ""
837+
$modifiedCommand = $modifiedCommand -replace ",\r?\n@CheckSum = '[YN]'", ""
804838
}
805839

806840
# Update job step if command was modified

tests/Install-DbaMaintenanceSolution.Tests.ps1

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ Describe $CommandName -Tag IntegrationTests {
156156
ReplaceExisting = $true
157157
CleanupTime = 168
158158
ChangeBackupType = $true
159-
Compress = $true
159+
Compress = "ForceOn"
160160
CopyOnly = $true
161-
Verify = $true
162-
CheckSum = $true
161+
Verify = "ForceOn"
162+
CheckSum = "ForceOn"
163163
ModificationLevel = 12
164164
}
165165
$installResult = Install-DbaMaintenanceSolution @splatInstall
@@ -387,10 +387,10 @@ Describe $CommandName -Tag IntegrationTests {
387387
ReplaceExisting = $true
388388
CleanupTime = 168
389389
ChangeBackupType = $false
390-
Compress = $false
390+
Compress = "ForceOff"
391391
CopyOnly = $false
392-
Verify = $false
393-
CheckSum = $false
392+
Verify = "ForceOff"
393+
CheckSum = "ForceOff"
394394
}
395395
$installResult = Install-DbaMaintenanceSolution @splatInstall
396396

@@ -613,10 +613,10 @@ Describe $CommandName -Tag IntegrationTests {
613613
ReplaceExisting = $true
614614
CleanupTime = 168
615615
ChangeBackupType = $false
616-
Compress = $false
616+
Compress = "ForceOff"
617617
CopyOnly = $false
618-
Verify = $true
619-
CheckSum = $false
618+
Verify = "ForceOn"
619+
CheckSum = "ForceOff"
620620
}
621621
$installResult = Install-DbaMaintenanceSolution @splatInstall
622622

@@ -781,13 +781,13 @@ Describe $CommandName -Tag IntegrationTests {
781781

782782
It "Should error out and tell us our mistake" {
783783
$splatInstall = @{
784-
SqlInstance = $TestConfig.InstanceMulti2
785-
Database = $testDbName
786-
InstallJobs = $true
787-
ReplaceExisting = $true
788-
Verify = $true
789-
BackupLocation = "NUL"
790-
EnableException = $true
784+
SqlInstance = $TestConfig.InstanceMulti2
785+
Database = $testDbName
786+
InstallJobs = $true
787+
ReplaceExisting = $true
788+
Verify = "ForceOn"
789+
BackupLocation = "NUL"
790+
EnableException = $true
791791
}
792792
$installResult = { Install-DbaMaintenanceSolution @splatInstall } | Should -Throw -ExpectedMessage '*NUL*'
793793
}
@@ -853,10 +853,10 @@ Describe $CommandName -Tag IntegrationTests {
853853
ReplaceExisting = $true
854854
CleanupTime = 168
855855
ChangeBackupType = $false
856-
Compress = $false
856+
Compress = "ForceOff"
857857
CopyOnly = $false
858-
Verify = $false
859-
CheckSum = $false
858+
Verify = "ForceOff"
859+
CheckSum = "ForceOff"
860860
}
861861
$installResult = Install-DbaMaintenanceSolution @splatInstall
862862

@@ -970,10 +970,10 @@ Describe $CommandName -Tag IntegrationTests {
970970
ReplaceExisting = $true
971971
CleanupTime = 168
972972
ChangeBackupType = $false
973-
Compress = $false
973+
Compress = "ForceOff"
974974
CopyOnly = $false
975-
Verify = $false
976-
CheckSum = $true
975+
Verify = "ForceOff"
976+
CheckSum = "ForceOn"
977977
}
978978
$installResult = Install-DbaMaintenanceSolution @splatInstall
979979

0 commit comments

Comments
 (0)