Skip to content

Commit 1f43cbb

Browse files
Install-DbaMaintenanceSolution: change Compress/Verify/CheckSum to ValidateSet string params (#10247)
1 parent 21a5220 commit 1f43cbb

2 files changed

Lines changed: 465 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

0 commit comments

Comments
 (0)