$ErrorActionPreference = 'Continue' $outFile = "G:\WEB-SERVER\htdocs\AttendanceHub\ZKTecoSyncService-V2\_deployment\deploy_20261009_results.txt" $r = New-Object System.Collections.Generic.List[string] $r.Add("deployStart=$(Get-Date -Format o)") # 1) Stop service Stop-Service ZKTecoSyncService -Force -ErrorAction SilentlyContinue $sw = [System.Diagnostics.Stopwatch]::StartNew() while ((Get-Service ZKTecoSyncService).Status -ne 'Stopped' -and $sw.Elapsed.TotalSeconds -lt 60) { Start-Sleep -Seconds 1 } $r.Add("after_stop: state=" + (Get-Service ZKTecoSyncService).Status) Start-Sleep -Seconds 3 foreach ($p in @(Get-Process AttendanceHub.Sync.Host -ErrorAction SilentlyContinue)) { Stop-Process -Id $p.Id -Force -ErrorAction SilentlyContinue Start-Sleep -Seconds 2 $r.Add("forced_exit_pid=$($p.Id)") } # 2) Backup old binaries (small, timestamps only for DLLs) $pub = "G:\WEB-SERVER\htdocs\AttendanceHub\ZKTecoSyncService-V2\publish" $bak = "G:\WEB-SERVER\htdocs\AttendanceHub\ZKTecoSyncService-V2\publish\bin_backup_pre_v2perf_20261009" New-Item -ItemType Directory -Force -Path $bak | Out-Null foreach ($f in @('AttendanceHub.Sync.dll','AttendanceHub.Sync.pdb','AttendanceHub.Sync.Host.dll','AttendanceHub.Sync.Host.exe','AttendanceHub.Sync.Host.pdb','AttendanceHub.Sync.Host.deps.json')) { Copy-Item (Join-Path $pub $f) (Join-Path $bak $f) -Force -ErrorAction SilentlyContinue } $r.Add("backup_done=$bak") # 3) Copy new binaries from build output $src = "G:\WEB-SERVER\htdocs\AttendanceHub\ZKTecoSyncService-V2\src\AttendanceHub.Sync.Host\bin\Release\net10.0-windows" foreach ($f in @('AttendanceHub.Sync.dll','AttendanceHub.Sync.pdb','AttendanceHub.Sync.Host.dll','AttendanceHub.Sync.Host.exe','AttendanceHub.Sync.Host.pdb','AttendanceHub.Sync.Host.deps.json')) { Copy-Item (Join-Path $src $f) (Join-Path $pub $f) -Force $r.Add("copied $f len=" + (Get-Item (Join-Path $pub $f)).Length) } # 4) Rotate old log (50MB) then truncate target so new run starts clean $log = Join-Path $pub "logs\attendancehub_sync.log" if (Test-Path $log) { $oldLen = (Get-Item $log).Length Move-Item $log "$log.pre_v2perf_20261009" -Force -ErrorAction SilentlyContinue $r.Add("log_rotated oldBytes=$oldLen") } # 5) Purge ingest_dedupe_log (151.8M rows / ~16GB) + VACUUM $r.Add("---- purge start $(Get-Date -Format o)") $db = Join-Path $pub "attendancehub_v2.db" $py = @' import sqlite3, sys, time db = sys.argv[1] t0 = time.time() con = sqlite3.connect(db, timeout=180) cur = con.cursor() cur.execute("PRAGMA journal_mode=OFF") cur.execute("PRAGMA synchronous=OFF") cur.execute("DROP TABLE IF EXISTS ingest_dedupe_log") con.commit() cur.execute("VACUUM") con.close() print("purge_ok seconds=%.1f" % (time.time()-t0)) '@ $pyFile = Join-Path $env:TEMP "purge_dedupe_20261009.py" Set-Content -Path $pyFile -Value $py -Encoding UTF8 $out = & python $pyFile $db 2>&1 $r.Add("purge_output: $out") $r.Add("db_size_after=" + (Get-Item $db).Length) Remove-Item $pyFile -Force -ErrorAction SilentlyContinue # 6) Start service $r.Add("---- start $(Get-Date -Format o)") & sc.exe start ZKTecoSyncService 2>&1 | Out-String | ForEach-Object { $r.Add($_.Trim()) } Start-Sleep -Seconds 10 $r.Add("final_state=" + (Get-Service ZKTecoSyncService).Status) $r.Add("final_pid=" + (Get-CimInstance Win32_Service -Filter "Name='ZKTecoSyncService'").ProcessId) $r.Add("deployEnd=$(Get-Date -Format o)") Set-Content -Path $outFile -Value ($r -join "`r`n") -Encoding UTF8