diff --git a/AGENTS.md b/AGENTS.md index 2f34c42..1a77e98 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -55,7 +55,7 @@ Key sections: - `StorageProvider` — `Azure` or `S3` - Azure: `storageAccountName`, `containerName`, `sasToken` - S3: `s3EndpointUrl`, `s3Region`, `s3BucketName`, `s3AccessKeyId`, `s3SecretAccessKey`, `s3ForcePathStyle` -- KHDB layout: `KhdbManifestPath`, `KhdbShardPrefix`, `KhdbLocalShardDir` +- KHDB layout: `KhdbManifestPath`, `KhdbShardPrefix`, `KhdbLocalShardDir`, `KhdbBackupCount` - App: `InstallationPath`, `ReportPathBase`, `WeakPasswordsDatabase`, `CheckOnlyEnabledUsers` - Lithnet: `LithnetStorePath`, `LithnetSyncHibp`, `LithnetHashSources`, `LithnetPlaintextSources`, `LithnetBannedWordSources` - Telemetry (optional): `UsageBeaconUrl`, `UsageBeaconMethod`, `UsageBeaconInstanceId`, `UsageBeaconTimeoutSeconds` diff --git a/CHANGELOG.md b/CHANGELOG.md index e2f96e5..04799b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ Starting with **v2.2.0**, Elysium uses a **unified project version**. All script ## [Unreleased] +### Changed +- **KHDB backups:** the previous `khdb.txt` is now moved aside instead of copied (instant instead of minutes for a 40+ GB file), and only the newest one is kept. `KhdbBackupCount` in `ElysiumSettings.txt` sets how many (default 1, `0` = none; was a fixed 5). + ### Fixed - **`Test-WeakADPasswords` spent hours checking the KHDB before testing:** `Resolve-DSInternalsWeakHashFile` validated the whole file with a per-line PowerShell loop, the same pattern that made the KHDB rebuild take hours. It now uses the compiled checker (`Elysium.KhdbText.Inspect` / `WriteNormalized`): one pass over a clean KHDB (about 1.6 s per 5 million hashes on pwsh 7) and no temporary copy. Files with blank or whitespace-padded lines are now normalized too; before, they were passed to DSInternals unchanged. - **KHDB rebuild took hours (or days) on Windows PowerShell 5.1:** the merged `khdb.txt` was built and validated with PowerShell code per hash line - a function call, a regex, a split and an uppercase conversion for every line, then a second regex pass to validate. Full-size KHDBs have hundreds of millions of lines. The merge and the validation now run in a small compiled class (`Elysium.KhdbMerger` / `Elysium.KhdbText`, built with `Add-Type` on 5.1 and 7, no extra install) with the same rules. 5 million hashes merge in about 4 s on pwsh 7; the 5.1 timing is still to be measured. The rebuild also prints progress per shard. diff --git a/ElysiumSettings.txt.sample b/ElysiumSettings.txt.sample index 664935a..7b38344 100644 --- a/ElysiumSettings.txt.sample +++ b/ElysiumSettings.txt.sample @@ -41,6 +41,8 @@ s3ForcePathStyle = true KhdbManifestPath=khdb/manifest.json KhdbShardPrefix=khdb/shards KhdbLocalShardDir=khdb-shards +# Previous khdb.txt copies (khdb.txt.bak-*) kept after a rebuild. Each is full size (tens of GB). 0 = none. +KhdbBackupCount=1 # Application Settings ###################### diff --git a/src/Elysium/Public/Update-ElysiumKhdb.ps1 b/src/Elysium/Public/Update-ElysiumKhdb.ps1 index 1b5836c..c6dbbe2 100644 --- a/src/Elysium/Public/Update-ElysiumKhdb.ps1 +++ b/src/Elysium/Public/Update-ElysiumKhdb.ps1 @@ -6,7 +6,8 @@ function Update-ElysiumKhdb { .DESCRIPTION Fetches the manifest from the configured storage (Azure Blob via SAS, or S3-compatible via SigV4), downloads only shards whose checksum changed, removes shards no longer listed, and - atomically replaces the merged KHDB file (keeping the 5 most recent backups). + replaces the merged KHDB file. The previous file is kept as khdb.txt.bak-