37 lines
1.5 KiB
PowerShell
37 lines
1.5 KiB
PowerShell
# Haelt zwei Replikations-Regeln fuer lxreplica in pg_hba.conf.
|
||
# Idempotent: entfernt immer alle lxreplica-Zeilen und setzt sie neu –
|
||
# verhindert Duplikate auch bei gleichzeitigen Schreibvorgaengen.
|
||
|
||
$pgCtl = "C:\Program Files\Lexware\PostgreSql\17\Bin\pg_ctl.exe"
|
||
$dataDir = "C:\ProgramData\Lexware\LexwarePG\Data\current"
|
||
$hbaFile = "$dataDir\pg_hba.conf"
|
||
|
||
$ruleAll = "hostssl all lxreplica 192.168.115.113/32 scram-sha-256"
|
||
$ruleRep = "hostssl replication lxreplica 192.168.115.113/32 scram-sha-256"
|
||
|
||
while ($true) {
|
||
try {
|
||
$lines = [System.IO.File]::ReadAllLines($hbaFile)
|
||
$existing = $lines | Where-Object { $_ -match "lxreplica" }
|
||
|
||
$alreadyCorrect = ($existing.Count -eq 2) -and
|
||
($existing[0] -eq $ruleAll) -and
|
||
($existing[1] -eq $ruleRep)
|
||
|
||
if (-not $alreadyCorrect) {
|
||
$base = $lines | Where-Object { $_ -notmatch "lxreplica" }
|
||
$newLines = [System.Collections.Generic.List[string]]::new()
|
||
foreach ($line in $base) {
|
||
if ($line -match "192\.168\.115\.0/24") {
|
||
$newLines.Add($ruleAll)
|
||
$newLines.Add($ruleRep)
|
||
}
|
||
$newLines.Add($line)
|
||
}
|
||
[System.IO.File]::WriteAllLines($hbaFile, $newLines, [System.Text.Encoding]::ASCII)
|
||
& $pgCtl reload -D $dataDir 2>&1 | Out-Null
|
||
}
|
||
} catch {}
|
||
Start-Sleep -Seconds 10
|
||
}
|