From 2b4ca5a8c67a293244ecf4017d450112c10fca99 Mon Sep 17 00:00:00 2001 From: Mike Swanson Date: Sat, 14 Mar 2026 15:28:10 -0700 Subject: [PATCH] scc: Session save and push from ACG-M-L5090 at 2026-03-14 08:45 Co-Authored-By: Claude Opus 4.6 --- .../sync-fixes/Sync-FromNAS-rsync.ps1 | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/projects/dataforth-dos/sync-fixes/Sync-FromNAS-rsync.ps1 b/projects/dataforth-dos/sync-fixes/Sync-FromNAS-rsync.ps1 index a9dd181..95c4b4a 100644 --- a/projects/dataforth-dos/sync-fixes/Sync-FromNAS-rsync.ps1 +++ b/projects/dataforth-dos/sync-fixes/Sync-FromNAS-rsync.ps1 @@ -185,6 +185,22 @@ function Import-ToDatabase { # Main Script # ============================================================================ +# -- Log rotation: cap at 10 MB, keep 5 archives -- +$LOG_MAX_BYTES = 10 * 1024 * 1024 +if (Test-Path $LOG_FILE) { + $logSize = (Get-Item $LOG_FILE).Length + if ($logSize -gt $LOG_MAX_BYTES) { + $archiveName = $LOG_FILE -replace '\.log$', "-$(Get-Date -Format 'yyyy-MM-dd-HHmmss').log" + Copy-Item $LOG_FILE $archiveName -Force + Clear-Content $LOG_FILE + # Keep only 5 most recent archives + $archives = Get-ChildItem (Split-Path $LOG_FILE) -Filter "sync-from-nas-*.log" | Sort-Object LastWriteTime -Descending + if ($archives.Count -gt 5) { + $archives | Select-Object -Skip 5 | Remove-Item -Force + } + } +} + Write-Log "==========================================" Write-Log "Starting sync (rsync mode)" if ($DryRun) { Write-Log "DRY RUN - no changes will be made" } @@ -290,7 +306,7 @@ foreach ($station in $nasStations) { # Lines starting with ">f" indicate a file was received foreach ($line in $result.Output) { $lineStr = "$line".Trim() - if ($lineStr -match '^>f.*\s(\S+\.DAT)$') { + if ($lineStr -match '(?i)^>f[\S.+]+\s+(\S+\.DAT)$') { $fileName = $Matches[1] $localFile = Join-Path $localDir $fileName Write-Log " Pulled: $station/LOGS/$logType/$fileName"