Skip to content

Commit 33f560c

Browse files
author
Uwe Janke
committed
v1.8.11.0: Fix New-sqmOlaUsrDbBackupJob exclude prefix - '!' was never valid Ola syntax
Ola Hallengren's DatabaseBackup only recognizes '-' as the exclude marker (DatabaseItem LIKE '-%'); '!' was introduced in v1.8.6.0 by mistake and never worked, causing exclusions to silently no-op and the resulting "do not exist" warning list to exceed RAISERROR's 2047-char substitution limit - masking the real failure in job history on BLBNBGFATDBA3. Fix prefix to '-' and add EXISTS(sys.databases) filter so only databases that actually exist on the target instance are added to the exclude list. Verified end-to-end on DEV02: full backup run, 0 "do not exist" messages, all active exclusions correctly skipped.
1 parent 241b94a commit 33f560c

3 files changed

Lines changed: 37 additions & 11 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.11.0] — 2026-07-02
4+
5+
### Bugfix
6+
7+
**`New-sqmOlaUsrDbBackupJob`** — Exclude-Prefix `!` war nie gueltige Ola-Syntax
8+
- Ursache eines echten Produktionsvorfalls (BLBNBGFATDBA3, `DatabaseBackup`-Job
9+
schlug fehl): der in v1.8.6.0 eingefuehrte `!`-Prefix fuer Exclusions
10+
(`USER_DATABASES,!db1,!db2`) wird von Ola Hallengrens `MaintenanceSolution.sql`
11+
nirgends ausgewertet — dort wird ausschliesslich `-db1` als Exclude-Marker
12+
erkannt (`DatabaseItem LIKE '-%'`). Alle `!`-Eintraege wurden dadurch als
13+
positive (nicht existierende) Datenbanknamen interpretiert: Exclusions griffen
14+
nie, und die daraus resultierende lange "do not exist"-Warnliste sprengte das
15+
2047-Zeichen-Limit von `RAISERROR('%s', ...)`, wodurch die eigentliche
16+
Fehlermeldung im Job-Verlauf unsichtbar wurde.
17+
- Fix: Prefix auf `-` korrigiert. Zusaetzlich Filter `EXISTS (SELECT 1 FROM
18+
sys.databases ...)`, sodass nur Datenbanken, die auf der jeweiligen Instanz
19+
tatsaechlich existieren, in die Exclude-Liste aufgenommen werden — verhindert
20+
erneutes Anwachsen der "do not exist"-Liste bei einer instanzuebergreifend
21+
gepflegten `sqm_BackupExclude`-Tabelle.
22+
- Verifiziert auf DEV02: kompletter FULL-Backup-Lauf ueber die neu generierte
23+
Prozedur, 0 "do not exist"-Meldungen, alle aktiven Exclusions korrekt
24+
uebersprungen.
25+
326
## [1.8.10.0] — 2026-07-02
427

528
### Bugfix

Public/New-sqmOlaUsrDbBackupJob.ps1

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
OlaJobNameLog (Default: 'OlaHH-UserDatabases-LOG')
1515
1616
When -UseExcludeTable is set, the function reads master.dbo.sqm_BackupExclude
17-
(created by Sync-sqmBackupExcludeTable) for entries where IsActive=1 AND IsOrphaned=0.
18-
If entries are found, they are prepended with '!' and appended to the @Databases parameter in the
19-
generated job step command. If the table does not exist or contains no matching rows,
17+
(created by Sync-sqmBackupExcludeTable) for entries where IsActive=1 AND IsOrphaned=0
18+
AND the database actually exists on this instance (sys.databases). If entries are found,
19+
they are prepended with '-' (Ola's exclude prefix) and appended to the @Databases parameter
20+
in the generated job step command. If the table does not exist or contains no matching rows,
2021
the -Databases parameter is used unchanged.
2122
2223
.PARAMETER SqlInstance
@@ -109,9 +110,10 @@
109110
Continue with remaining jobs if one job fails.
110111
111112
.PARAMETER UseExcludeTable
112-
When set, reads master.dbo.sqm_BackupExclude for active, non-orphaned entries and
113-
adds them as '!DatabaseName' exclusions to the @Databases parameter of Ola's DatabaseBackup.
114-
If the table does not exist or is empty, the Databases parameter is used unchanged.
113+
When set, reads master.dbo.sqm_BackupExclude for active, non-orphaned entries that exist
114+
on this instance and adds them as '-DatabaseName' exclusions to the @Databases parameter
115+
of Ola's DatabaseBackup. If the table does not exist or is empty, the Databases parameter
116+
is used unchanged.
115117
116118
.PARAMETER CreateSyncJob
117119
When -UseExcludeTable is set, automatically creates a SQL Agent job that runs
@@ -556,10 +558,11 @@ BEGIN
556558
BEGIN
557559
DECLARE @Exclusions NVARCHAR(MAX);
558560
SELECT @Exclusions = STUFF((
559-
SELECT ',' + '!' + DatabaseName
560-
FROM master.dbo.sqm_BackupExclude
561-
WHERE IsActive = 1
562-
AND IsOrphaned = 0
561+
SELECT ',-' + e.DatabaseName
562+
FROM master.dbo.sqm_BackupExclude e
563+
WHERE e.IsActive = 1
564+
AND e.IsOrphaned = 0
565+
AND EXISTS (SELECT 1 FROM sys.databases d WHERE d.name = e.DatabaseName)
563566
FOR XML PATH(''), TYPE
564567
).value('.', 'NVARCHAR(MAX)'), 1, 1, '');
565568
IF @Exclusions IS NOT NULL AND @Exclusions <> ''

sqmSQLTool.psd1

Lines changed: 1 addition & 1 deletion
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.10.0'
20+
ModuleVersion = '1.8.11.0'
2121

2222
# ID used to uniquely identify this module
2323
GUID = 'c4b10ba2-aee2-4d8d-ad86-a6e97c346ba6'

0 commit comments

Comments
 (0)