Skip to content

Commit e37d656

Browse files
Uwe Jankeclaude
andcommitted
fix: OLA job names and BackupDirectory auto-detection
- New-sqmOlaUsrDbBackupJob: fix regex to match @Directory in UseExcludeTable job steps (N''path'' double-quote format in dynamic SQL) - Set-sqmConfig: save only explicitly-set keys to config.json (merge instead of full dump) — prevents OlaHH defaults from overwriting FITS job names - sqmSQLTool.psm1: load config.json before FI-TS overrides (Step 1b/1c swap) so FI-TS environment values always win over stale config.json entries - Version 1.8.4.0 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent dfbf316 commit e37d656

4 files changed

Lines changed: 51 additions & 27 deletions

File tree

Public/New-sqmOlaUsrDbBackupJob.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ function New-sqmOlaUsrDbBackupJob
320320
if (-not $PSBoundParameters.ContainsKey('BackupDirectory'))
321321
{
322322
$existStep = $existingFullJob.JobSteps | Select-Object -First 1
323-
if ($existStep -and $existStep.Command -match "@Directory\s*=\s*N?'([^']+)'")
323+
if ($existStep -and $existStep.Command -match "@Directory\s*=\s*N?'{1,2}([^']+)'{1,2}")
324324
{
325325
$BackupDirectory = $Matches[1] -replace '\\Usr-db$', ''
326326
Invoke-sqmLogging -Message "BackupDirectory aus vorhandenem Job: $BackupDirectory" -FunctionName $functionName -Level "INFO"

Public/Set-sqmConfig.ps1

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,14 +462,38 @@ function Set-sqmConfig
462462
return
463463
}
464464

465-
# Persistenz: JSON-Datei schreiben
465+
# Persistenz: Nur explizit gesetzte Keys in JSON-Datei schreiben (Merge)
466+
# Verhindert, dass Auto-Werte (FI-TS-Defaults, Umgebungsvariablen) in config.json
467+
# landen und beim naechsten Modulimport den FI-TS-Block ueberschreiben.
466468
$configFile = Join-Path $env:APPDATA "MSSQLTools\config.json"
467469
$configDir = Split-Path $configFile -Parent
468470
if (-not (Test-Path $configDir))
469471
{
470472
New-Item -ItemType Directory -Path $configDir -Force | Out-Null
471473
}
472-
$globalConfig | ConvertTo-Json -Depth 10 | Set-Content -Path $configFile -Force
474+
475+
# Bestehende config.json einlesen (nur user-gesetzte Keys)
476+
$persistConfig = [ordered]@{}
477+
if (Test-Path $configFile)
478+
{
479+
try
480+
{
481+
$existingJson = Get-Content $configFile -Raw | ConvertFrom-Json
482+
foreach ($prop in $existingJson.PSObject.Properties) { $persistConfig[$prop.Name] = $prop.Value }
483+
}
484+
catch { }
485+
}
486+
487+
# Nur in diesem Aufruf explizit geaenderte Keys uebernehmen
488+
foreach ($paramName in $PSBoundParameters.Keys)
489+
{
490+
if ($globalConfig.ContainsKey($paramName))
491+
{
492+
$persistConfig[$paramName] = $globalConfig[$paramName]
493+
}
494+
}
495+
496+
$persistConfig | ConvertTo-Json -Depth 10 | Set-Content -Path $configFile -Force
473497
Write-Verbose "Konfiguration gespeichert: $configFile"
474498

475499
if ($PassThru)

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.3.0'
20+
ModuleVersion = '1.8.4.0'
2121

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

sqmSQLTool.psm1

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,30 @@ if (Test-Path $manifestPath)
7272
}
7373

7474
# =============================================================================
75-
# SCHRITT 1b: FI-TS-Umgebungserkennung
75+
# SCHRITT 1b: Persistierte Konfiguration laden (ueberschreibt Standardwerte)
76+
# =============================================================================
77+
$configFile = Join-Path $env:APPDATA "MSSQLTools\config.json"
78+
if (Test-Path $configFile)
79+
{
80+
try
81+
{
82+
$userConfig = Get-Content $configFile -Raw | ConvertFrom-Json
83+
foreach ($key in $userConfig.PSObject.Properties)
84+
{
85+
$script:sqmModuleConfig[$key.Name] = $key.Value
86+
}
87+
}
88+
catch
89+
{
90+
Write-Warning "Konfiguration konnte nicht geladen werden: $($_.Exception.Message)"
91+
}
92+
}
93+
94+
# =============================================================================
95+
# SCHRITT 1c: FI-TS-Umgebungserkennung (ueberschreibt config.json — gewinnt immer)
7696
# Kriterium 1: Modul liegt auf W:\ (FI-TS Netzlaufwerk)
7797
# Kriterium 2: Angemeldeter Benutzer ist in Domaene OFFICELAN.IZB / OFFICELAN
78-
# Wenn erkannt: FI-TS-Standardwerte setzen (config.json ueberschreibt weiterhin).
98+
# FI-TS-Werte werden NACH config.json gesetzt und haben stets Vorrang.
7999
# =============================================================================
80100
$script:sqmIsFitsEnvironment = $false
81101

@@ -117,34 +137,14 @@ if ($script:sqmIsFitsEnvironment)
117137
$script:sqmModuleConfig['OlaJobNameOutputCleanup'] = 'FITS Output File Cleanup'
118138
$script:sqmModuleConfig['OlaJobNamePurgeJobHistory'] = 'FITS sp_purge_jobhistory'
119139
$script:sqmModuleConfig['OlaJobNameDeleteBackupHistory'] = 'FITS sp_delete_backuphistory'
120-
# FI-TS Check-Profil und Grenzwerte (identisch mit Defaults, explizit gesetzt fuer Ueberschreibbarkeit)
140+
# FI-TS Check-Profil und Grenzwerte
121141
$script:sqmModuleConfig['CheckProfile'] = 'FiTs'
122142
$script:sqmModuleConfig['CheckCostThresholdMin'] = 50
123143
$script:sqmModuleConfig['CheckTempDbMaxFiles'] = 8
124144
$script:sqmModuleConfig['CheckDiskBlockSize'] = 65536
125145
$script:sqmModuleConfig['DiskFreeSpaceThresholdPct'] = 10
126146
}
127147

128-
# =============================================================================
129-
# SCHRITT 1c: Persistierte Konfiguration laden (ueberschreibt alle Standardwerte)
130-
# =============================================================================
131-
$configFile = Join-Path $env:APPDATA "MSSQLTools\config.json"
132-
if (Test-Path $configFile)
133-
{
134-
try
135-
{
136-
$userConfig = Get-Content $configFile -Raw | ConvertFrom-Json
137-
foreach ($key in $userConfig.PSObject.Properties)
138-
{
139-
$script:sqmModuleConfig[$key.Name] = $key.Value
140-
}
141-
}
142-
catch
143-
{
144-
Write-Warning "Konfiguration konnte nicht geladen werden: $($_.Exception.Message)"
145-
}
146-
}
147-
148148
# String-Cache invalidieren (wird durch Get-sqmString bei erstem Zugriff neu befuellt)
149149
$script:_strings = $null
150150

0 commit comments

Comments
 (0)