31 lines
1.4 KiB
PowerShell
31 lines
1.4 KiB
PowerShell
$ErrorActionPreference='Continue'
|
|
$src='C:\Share\Quickbooks'
|
|
$dst='\\TPS-SVR\Share\Quickbooks'
|
|
$qbw='schoonerQB2025.QBW'
|
|
$tlg='schoonerQB2025.QBW.TLG'
|
|
|
|
"== stop QB hosting services (prevents re-lock during copy) =="
|
|
foreach($s in 'QuickBooksDB34','QBCFMonitorService'){ Stop-Service $s -Force -ErrorAction SilentlyContinue; Start-Sleep 1; "$s -> $((Get-Service $s -ErrorAction SilentlyContinue).Status)" }
|
|
Start-Sleep 3
|
|
|
|
try {
|
|
"== confirm company file is unlocked =="
|
|
try { $fs=[System.IO.File]::Open((Join-Path $src $qbw),'Open','Read','None'); $fs.Close(); "UNLOCKED - copying" }
|
|
catch { "STILL LOCKED: $($_.Exception.Message)" }
|
|
|
|
"== copy clean company file + transaction log =="
|
|
$out = robocopy $src $dst $qbw $tlg /COPY:DAT /R:2 /W:3 /NP /NJH
|
|
($out | Select-String 'schoonerQB2025|Bytes :|ERROR|New File') | Out-String
|
|
"robocopy exit code: $LASTEXITCODE (0-7 = success)"
|
|
}
|
|
finally {
|
|
"== restart QB services (users resume on OLD server) =="
|
|
foreach($s in 'QBCFMonitorService','QuickBooksDB34'){ Start-Service $s -ErrorAction SilentlyContinue; Start-Sleep 1; "$s -> $((Get-Service $s -ErrorAction SilentlyContinue).Status)" }
|
|
}
|
|
|
|
"== verify copied file matches source =="
|
|
$s=(Get-Item (Join-Path $src $qbw) -ErrorAction SilentlyContinue).Length
|
|
$d=(Get-Item (Join-Path $dst $qbw) -ErrorAction SilentlyContinue).Length
|
|
"SRC: $([math]::Round($s/1MB,1)) MB DST: $([math]::Round($d/1MB,1)) MB MATCH: $($s -eq $d -and $s -gt 0)"
|
|
"== DONE =="
|