From 867fb6427ddd9226b765e359da3a01db6a1fb971 Mon Sep 17 00:00:00 2001 From: Tomas Kracmar Date: Wed, 29 Jul 2026 11:53:26 +0200 Subject: [PATCH] fix(Update-KHDB): cap KHDB backup retention Every successful update created a new khdb.txt.bak- with no cleanup anywhere, so a recurring scheduled job accumulated one full-size backup per run indefinitely. Now keeps only the 5 most recent backups, pruning older ones after each new backup is created. Co-Authored-By: Claude Sonnet 5 --- Update-KHDB.ps1 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Update-KHDB.ps1 b/Update-KHDB.ps1 index 674c78f..6bb0526 100644 --- a/Update-KHDB.ps1 +++ b/Update-KHDB.ps1 @@ -773,6 +773,15 @@ function Update-KHDB { $backupPath = Join-Path -Path $installPath -ChildPath ("$khdbName.bak-$ts") Copy-Item -LiteralPath $combinedTarget -Destination $backupPath -Force Write-Host ("Existing KHDB backed up to {0}" -f $backupPath) + + # Each run adds one full-size backup; keep only the most recent few so a recurring + # scheduled job doesn't silently accumulate backups until the disk fills up. + $backupRetentionCount = 5 + $staleBackups = Get-ChildItem -LiteralPath $installPath -Filter "$khdbName.bak-*" -File -ErrorAction SilentlyContinue | + Sort-Object Name -Descending | Select-Object -Skip $backupRetentionCount + foreach ($stale in $staleBackups) { + try { Remove-Item -LiteralPath $stale.FullName -Force } catch { Write-Warning "Could not remove old backup '$($stale.FullName)': $($_.Exception.Message)" } + } } Move-Item -LiteralPath $combinedTemp -Destination $combinedTarget -Force