Skip to content

Commit b82f01e

Browse files
authored
Install-DbaMaintenanceSolution: make off switches work and increase test coverage (#10172)
1 parent 1a510a1 commit b82f01e

2 files changed

Lines changed: 796 additions & 20 deletions

File tree

public/Install-DbaMaintenanceSolution.ps1

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function Install-DbaMaintenanceSolution {
102102
Only applies when InstallJobs is specified.
103103
104104
.PARAMETER ModificationLevel
105-
Specifies minimum modification percentage required before ChangeBackupType converts a differential or log backup to full backup.
105+
Specifies minimum modification percentage required before ChangeBackupType converts a differential backup to full backup.
106106
Valid range: 0-100. Use this with ChangeBackupType to control when backup type changes occur based on data modification levels.
107107
Only applies when InstallJobs is specified.
108108
@@ -312,6 +312,11 @@ function Install-DbaMaintenanceSolution {
312312
return
313313
}
314314

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."
317+
return
318+
}
319+
315320
if ((Test-Bound -ParameterName CleanupTime) -and -not $InstallJobs) {
316321
Stop-Function -Message "CleanupTime is only useful when installing jobs. To install jobs, please use '-InstallJobs' in addition to CleanupTime."
317322
return
@@ -729,7 +734,7 @@ function Install-DbaMaintenanceSolution {
729734
}
730735

731736
# Modify backup job steps to include additional parameters
732-
if ($InstallJobs -and ($ChangeBackupType -or $Compress -or $CopyOnly -or $Verify -or $CheckSum -or $ModificationLevel)) {
737+
if ($InstallJobs) {
733738
Write-ProgressHelper -ExcludePercent -Message "Applying additional backup parameters to job steps"
734739

735740
$null = $server.Refresh()
@@ -756,17 +761,23 @@ function Install-DbaMaintenanceSolution {
756761
}
757762

758763
# Add ModificationLevel parameter for jobs with ChangeBackupType
759-
if ($ModificationLevel -gt 0 -and ($job.Name -match "DIFF|LOG")) {
764+
if ($ModificationLevel -gt 0 -and ($job.Name -match "DIFF")) {
760765
if ($modifiedCommand -notmatch "@ModificationLevel") {
761766
$modifiedCommand = $modifiedCommand -replace "(@LogToTable = '[YN]')", "`$1,$([System.Environment]::NewLine)@ModificationLevel = $ModificationLevel"
762767
}
763768
}
764769

765770
# Add Compress parameter for all backup jobs
766771
if ($Compress) {
772+
$modifiedCommand = $modifiedCommand -replace "@Compress = 'N'", "@Compress = 'Y'"
767773
if ($modifiedCommand -notmatch "@Compress") {
768774
$modifiedCommand = $modifiedCommand -replace "(@LogToTable = '[YN]')", "`$1,$([System.Environment]::NewLine)@Compress = 'Y'"
769775
}
776+
} else {
777+
$modifiedCommand = $modifiedCommand -replace "@Compress = 'Y'", "@Compress = 'N'"
778+
if ($modifiedCommand -notmatch "@Compress") {
779+
$modifiedCommand = $modifiedCommand -replace "(@LogToTable = '[YN]')", "`$1,$([System.Environment]::NewLine)@Compress = 'N'"
780+
}
770781
}
771782

772783
# Add CopyOnly parameter for all backup jobs
@@ -777,16 +788,18 @@ function Install-DbaMaintenanceSolution {
777788
}
778789

779790
# Add Verify parameter for all backup jobs
780-
if ($Verify) {
781-
if ($modifiedCommand -notmatch "@Verify") {
782-
$modifiedCommand = $modifiedCommand -replace "(@LogToTable = '[YN]')", "`$1,$([System.Environment]::NewLine)@Verify = 'Y'"
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'"
783795
}
784796
}
785797

786798
# Add CheckSum parameter for all backup jobs
787-
if ($CheckSum) {
788-
if ($modifiedCommand -notmatch "@CheckSum") {
789-
$modifiedCommand = $modifiedCommand -replace "(@LogToTable = '[YN]')", "`$1,$([System.Environment]::NewLine)@CheckSum = 'Y'"
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'"
790803
}
791804
}
792805

@@ -823,4 +836,4 @@ function Install-DbaMaintenanceSolution {
823836
Write-ProgressHelper -ExcludePercent -Message "Installation complete"
824837
Write-ProgressHelper -Completed
825838
}
826-
}
839+
}

0 commit comments

Comments
 (0)