Skip to content

Commit c7c4652

Browse files
Uwe Jankeclaude
andcommitted
v1.8.5.0: New-sqmOlaUsrDbBackupJob — CreateSyncJob parameter
Adds -CreateSyncJob [bool] (default $true) to New-sqmOlaUsrDbBackupJob. When -UseExcludeTable is active, automatically creates a SQL Agent job (sqm BackupExclude - SYNC / FITS BackupExclude - SYNC) that runs Sync-sqmBackupExcludeTable every 30 minutes via pwsh CmdExec step. Ensures IsActive changes from Show-sqmBackupExcludeForm propagate to AG secondaries without manual intervention. Job is propagated to all AlwaysOn secondaries during recursive call. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 5909999 commit c7c4652

3 files changed

Lines changed: 122 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
# sqmSQLTool — Changelog
22

3+
## [1.8.5.0] — 2026-07-01
4+
5+
### Erweiterungen
6+
7+
**`New-sqmOlaUsrDbBackupJob`**
8+
- Neu: Parameter `-CreateSyncJob` (`[bool]`, Default `$true`).
9+
Wenn `-UseExcludeTable` aktiv ist, wird automatisch ein SQL Agent Job
10+
(`sqm BackupExclude - SYNC` bzw. `FITS BackupExclude - SYNC` in FI-TS-Umgebungen) angelegt.
11+
Der Job laeuft alle 30 Minuten via `pwsh`-CmdExec-Step und ruft
12+
`Sync-sqmBackupExcludeTable -SqlInstance '.'` auf. Stellt sicher, dass `IsActive`-Aenderungen
13+
aus `Show-sqmBackupExcludeForm` ohne manuellen Eingriff auf alle AG-Secondaries propagiert werden.
14+
Der Job wird bei `-Update` aktualisiert; bei `-CreateSyncJob $false` wird er nicht angelegt.
15+
Job-Name leitet sich aus dem FULL-Job-Praefix ab (`FITS *` → FITS, sonst Standard).
16+
AG-Propagation: Secundaries erhalten ebenfalls den Sync-Job (rekursiver Aufruf mit gesetztem
17+
`CreateSyncJob = $CreateSyncJob`).
18+
19+
**`New-sqmOlaUsrDbBackupJob`** — Konfigurationsfehler behoben (v1.8.4.0)
20+
- Fix: `Set-sqmConfig` schrieb zuvor die gesamte `$globalConfig` in `config.json`, wodurch
21+
auf FI-TS-Maschinen die OlaHH-Jobnamen aus einer frueheren Non-FITS-Session die FITS-Namen
22+
ueberschrieben. Fix (A): `Set-sqmConfig` speichert nur explizit uebergebene Keys (Merge).
23+
Fix (B): In `sqmSQLTool.psm1` wird `config.json` vor dem FI-TS-Block geladen —
24+
FI-TS-Override gewinnt immer.
25+
326
## [1.8.3.0] — 2026-06-29
427

528
### Bugfixes & Erweiterungen

Public/New-sqmOlaUsrDbBackupJob.ps1

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@
113113
adds them as @ExcludeDatabases to the Ola DatabaseBackup command in the job step.
114114
If the table does not exist or is empty, the Databases parameter is used unchanged.
115115
116+
.PARAMETER CreateSyncJob
117+
When -UseExcludeTable is set, automatically creates a SQL Agent job that runs
118+
Sync-sqmBackupExcludeTable every 30 minutes via pwsh CmdExec step.
119+
Ensures IsActive changes (made via Show-sqmBackupExcludeForm) are propagated
120+
to all AG secondaries without manual intervention.
121+
Default: $true. Set to $false to suppress job creation.
122+
116123
.PARAMETER EnableException
117124
Throw exceptions immediately.
118125
@@ -262,6 +269,8 @@ function New-sqmOlaUsrDbBackupJob
262269
[Parameter(Mandatory = $false)]
263270
[switch]$UseExcludeTable,
264271
[Parameter(Mandatory = $false)]
272+
[bool]$CreateSyncJob = $true,
273+
[Parameter(Mandatory = $false)]
265274
[switch]$SkipAlwaysOnPropagation,
266275
[Parameter(Mandatory = $false)]
267276
[switch]$EnableException
@@ -291,6 +300,7 @@ function New-sqmOlaUsrDbBackupJob
291300
$effFullJobName = if ($FullJobName) { $FullJobName } elseif ($cfg['OlaJobNameFull']) { $cfg['OlaJobNameFull'] } else { 'OlaHH-UserDatabases-FULL' }
292301
$effDiffJobName = if ($DiffJobName) { $DiffJobName } elseif ($cfg['OlaJobNameDiff']) { $cfg['OlaJobNameDiff'] } else { 'OlaHH-UserDatabases-DIFF' }
293302
$effLogJobName = if ($LogJobName) { $LogJobName } elseif ($cfg['OlaJobNameLog']) { $cfg['OlaJobNameLog'] } else { 'OlaHH-UserDatabases-LOG' }
303+
$syncJobName = if ($effFullJobName -like 'FITS *') { 'FITS BackupExclude - SYNC' } else { 'sqm BackupExclude - SYNC' }
294304

295305
$connParams = @{ SqlInstance = $SqlInstance }
296306
if ($SqlCredential) { $connParams['SqlCredential'] = $SqlCredential }
@@ -729,8 +739,92 @@ EXECUTE master.dbo.DatabaseBackup
729739

730740
$results.Add($result)
731741
}
732-
733-
# 7. Konfigurationsbericht schreiben
742+
743+
# 7. Sync-Job fuer sqm_BackupExclude anlegen (nur bei -UseExcludeTable -CreateSyncJob)
744+
if ($UseExcludeTable -and $CreateSyncJob)
745+
{
746+
try
747+
{
748+
$syncJobExists = Get-DbaAgentJob @connParams -Job $syncJobName -ErrorAction SilentlyContinue
749+
if ($syncJobExists -and -not $Update)
750+
{
751+
Invoke-sqmLogging -Message "Sync-Job '$syncJobName' existiert bereits (kein -Update — unveraendert)." -FunctionName $functionName -Level "INFO"
752+
}
753+
elseif ($PSCmdlet.ShouldProcess($SqlInstance, "Erstelle Sync-Job '$syncJobName' (alle 30 Min.)"))
754+
{
755+
$syncStepCmd = "pwsh -NonInteractive -NoProfile -Command `"& { Import-Module sqmSQLTool; Sync-sqmBackupExcludeTable -SqlInstance '.' }`""
756+
757+
if (-not $syncJobExists)
758+
{
759+
New-DbaAgentJob @connParams `
760+
-Job $syncJobName `
761+
-Category $JobCategory `
762+
-OwnerLogin $saLogin `
763+
-Description "sqmSQLTool: Synchronisiert master.dbo.sqm_BackupExclude und propagiert Aenderungen auf AG-Secondaries." `
764+
-ErrorAction Stop | Out-Null
765+
}
766+
767+
$existingStep = if ($syncJobExists) { $syncJobExists.JobSteps | Where-Object { $_.ID -eq 1 } } else { $null }
768+
if ($existingStep)
769+
{
770+
Set-DbaAgentJobStep @connParams -Job $syncJobName -StepId 1 -Command $syncStepCmd -SubSystem CmdExec -ErrorAction Stop | Out-Null
771+
}
772+
else
773+
{
774+
New-DbaAgentJobStep @connParams -Job $syncJobName -StepId 1 -StepName 'Sync sqm_BackupExclude' -Command $syncStepCmd -SubSystem CmdExec -ErrorAction Stop | Out-Null
775+
}
776+
777+
if (-not $syncJobExists)
778+
{
779+
New-DbaAgentSchedule @connParams `
780+
-Job $syncJobName `
781+
-Schedule "${syncJobName}_30min" `
782+
-FrequencyType Daily `
783+
-FrequencyInterval 1 `
784+
-FrequencySubdayType Minutes `
785+
-FrequencySubdayInterval 30 `
786+
-StartTime '000000' `
787+
-Force `
788+
-ErrorAction Stop | Out-Null
789+
}
790+
791+
$syncAction = if ($syncJobExists) { 'aktualisiert' } else { 'erstellt' }
792+
$syncMsg = "Sync-Job '$syncJobName' $syncAction — laeuft taeglich alle 30 Minuten."
793+
Invoke-sqmLogging -Message $syncMsg -FunctionName $functionName -Level "INFO"
794+
$results.Add([PSCustomObject]@{
795+
SqlInstance = $SqlInstance
796+
BackupType = 'SYNC'
797+
JobName = $syncJobName
798+
BackupDirectory = $null
799+
Databases = $null
800+
ScheduleTime = '00:00'
801+
ScheduleDays = 'EveryDay (alle 30 Min.)'
802+
JobStatus = if ($syncJobExists) { 'Updated' } else { 'Created' }
803+
OverallStatus = 'Success'
804+
Message = $syncMsg
805+
})
806+
}
807+
}
808+
catch
809+
{
810+
$errMsg = "Sync-Job '$syncJobName' konnte nicht erstellt werden: $($_.Exception.Message)"
811+
Invoke-sqmLogging -Message $errMsg -FunctionName $functionName -Level "WARNING"
812+
$results.Add([PSCustomObject]@{
813+
SqlInstance = $SqlInstance
814+
BackupType = 'SYNC'
815+
JobName = $syncJobName
816+
BackupDirectory = $null
817+
Databases = $null
818+
ScheduleTime = $null
819+
ScheduleDays = $null
820+
JobStatus = 'Failed'
821+
OverallStatus = 'Warning'
822+
Message = $errMsg
823+
})
824+
}
825+
}
826+
827+
# 8. Konfigurationsbericht schreiben
734828
if (-not (Test-Path $maintenanceLogDir)) { New-Item -ItemType Directory -Path $maintenanceLogDir -Force | Out-Null }
735829
$safeInst = $SqlInstance -replace '[\\/:*?"<>|]', '_'
736830
$datestamp = Get-Date -Format 'yyyy-MM-dd'
@@ -799,6 +893,7 @@ EXECUTE master.dbo.DatabaseBackup
799893
}
800894
if ($SqlCredential) { $secParams['SqlCredential'] = $SqlCredential }
801895
if ($UseExcludeTable) { $secParams['UseExcludeTable'] = $true }
896+
$secParams['CreateSyncJob'] = $CreateSyncJob
802897
if ($OperatorName) { $secParams['OperatorName'] = $OperatorName }
803898
if ($BackupDirectory) { $secParams['BackupDirectory'] = $BackupDirectory }
804899

sqmSQLTool.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
RootModule = 'sqmSQLTool.psm1'
1818

1919
# Version number of this module.
20-
ModuleVersion = '1.8.4.0'
20+
ModuleVersion = '1.8.5.0'
2121

2222
# ID used to uniquely identify this module
2323
GUID = 'c4b10ba2-aee2-4d8d-ad86-a6e97c346ba6'
@@ -249,7 +249,7 @@
249249
# IconUri = ''
250250

251251
# ReleaseNotes of this module
252-
ReleaseNotes = 'See CHANGELOG.md and GitHub: https://github.com/JankeUwe/sqmSQLTool/releases/tag/v1.8.2.0'
252+
ReleaseNotes = 'See CHANGELOG.md and GitHub: https://github.com/JankeUwe/sqmSQLTool/releases/tag/v1.8.5.0'
253253

254254
# External module dependencies
255255
ExternalModuleDependencies = @('dbatools')

0 commit comments

Comments
 (0)