|
438 | 438 | DIFF = if ($cfg['OlaJobNameDiff']) { $cfg['OlaJobNameDiff'] } else { 'OlaHH-UserDatabases-DIFF' } |
439 | 439 | } |
440 | 440 |
|
441 | | - # Liest einen benannten Ola-Parameter aus dem Step-Command (static + dynamic T-SQL) |
| 441 | + # Liest einen benannten Ola-Parameter aus T-SQL (Step-Command oder Proc-Body) |
442 | 442 | $parseParam = { |
443 | | - param ([string]$cmd, [string]$p) |
444 | | - if ($cmd -match "(?i)@$p\s*=\s*(?:N?'{1,2})([^']+)") { $Matches[1] } else { '—' } |
| 443 | + param ([string]$sql, [string]$p) |
| 444 | + # Databases: auch DECLARE-Variante abfangen (UseExcludeTable-Architektur) |
| 445 | + if ($p -eq 'Databases' -and $sql -match "(?i)DECLARE\s+@Databases\s+\w+(?:\([^)]+\))?\s*=\s*N?'([^']+)'") { |
| 446 | + return $Matches[1] |
| 447 | + } |
| 448 | + if ($sql -match "(?i)@$p\s*=\s*(?:N?'{1,2})([^']+)") { $Matches[1] } else { '—' } |
445 | 449 | } |
446 | 450 |
|
447 | 451 | $lines = [System.Collections.Generic.List[string]]::new() |
|
491 | 495 | } |
492 | 496 | else { $schedStr = 'kein Schedule' } |
493 | 497 |
|
494 | | - # Step-Command |
| 498 | + # Step-Command lesen |
495 | 499 | $cmd = '' |
496 | 500 | $step = $job.JobSteps | Where-Object { $_.ID -eq 1 } |
497 | 501 | if ($step) { $cmd = $step.Command } |
498 | 502 |
|
499 | | - $db = & $parseParam $cmd 'Databases' |
500 | | - $dir = & $parseParam $cmd 'Directory' |
501 | | - $cleanup = if ($cmd -match '(?i)@CleanupTime\s*=\s*(\d+)') { $Matches[1] } else { '—' } |
502 | | - $compress = & $parseParam $cmd 'Compress' |
503 | | - $verify = & $parseParam $cmd 'Verify' |
504 | | - $checksum = & $parseParam $cmd 'CheckSum' |
505 | | - $hasExclude = $cmd -match 'sqm_BackupExclude' |
| 503 | + # Neue Architektur: Step ruft Prozedur — Proc-Body fuer Parameter-Parse laden |
| 504 | + $sqlToparse = $cmd |
| 505 | + if ($cmd -match '(?i)EXEC\s+master\.dbo\.\[([^\]]+)\]') |
| 506 | + { |
| 507 | + $procDef = Invoke-DbaQuery @script:connParams -Database master ` |
| 508 | + -Query "SELECT OBJECT_DEFINITION(OBJECT_ID(N'[$($Matches[1])]', N'P')) AS Def" ` |
| 509 | + -ErrorAction SilentlyContinue |
| 510 | + if ($procDef -and $procDef.Def) { $sqlToparse = $procDef.Def } |
| 511 | + } |
| 512 | + |
| 513 | + $db = & $parseParam $sqlToparse 'Databases' |
| 514 | + $dir = & $parseParam $sqlToparse 'Directory' |
| 515 | + $cleanup = if ($sqlToparse -match '(?i)@CleanupTime\s*=\s*(\d+)') { $Matches[1] } else { '—' } |
| 516 | + $compress = & $parseParam $sqlToparse 'Compress' |
| 517 | + $verify = & $parseParam $sqlToparse 'Verify' |
| 518 | + $checksum = & $parseParam $sqlToparse 'CheckSum' |
| 519 | + $hasExclude = $sqlToparse -match 'sqm_BackupExclude' |
506 | 520 |
|
507 | 521 | $lines.Add(" [$type] $jobName | Schedule: $schedStr") |
508 | 522 | $lines.Add(" @Databases=$db @Directory=$dir @CleanupTime=${cleanup}h") |
|
0 commit comments