forked from admin/dyolink
fix(backup): run SSH with -v and read the exit code so the Windows copy finishes
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -154,7 +154,7 @@ The staging PC pulls the same folder three times a day, 30 minutes after each pr
|
||||
|
||||
The folder on the PC mirrors the server folder. After a run where every copy succeeded, a `nudentic_*.dump` on the PC that is no longer on the server is deleted (about 3 days of dumps are left). If the server list is empty or any copy fails, nothing is deleted. The Mac copy is the longer archive. This stores files only. It does not load them into the staging database, and it does not change the production server.
|
||||
|
||||
The script is [`scripts/copy-prod-backup.ps1`](scripts/copy-prod-backup.ps1). It reads the production SSH password from `C:\dyolink\secrets\nudentic-ssh-password.txt`. A scheduled task has no person to type it. The password file is the full `dyolink` login. Do not commit it. SSH is started with no window. A window makes SSH wait for a password that nobody can see, and `copy.log` stays on `Starting copy from production.`
|
||||
The script is [`scripts/copy-prod-backup.ps1`](scripts/copy-prod-backup.ps1). It reads the production SSH password from `C:\dyolink\secrets\nudentic-ssh-password.txt`. A scheduled task has no person to type it. The password file is the full `dyolink` login. Do not commit it. SSH is started hidden with `-v`. On the staging PC a hidden run without `-v` waits forever and `copy.log` stays on `Starting copy from production.`; with `-v` it finishes in about 8 seconds (the password helper needs that long to start).
|
||||
|
||||
A deploy does not install this. On the Windows PC, from a checkout of the repo:
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ function Invoke-OpenSsh([string]$Exe, [string[]]$ArgumentList) {
|
||||
$outFile = Join-Path $env:TEMP "dyolink-ssh-out-$stamp.txt"
|
||||
$errFile = Join-Path $env:TEMP "dyolink-ssh-err-$stamp.txt"
|
||||
$proc = Start-Process -FilePath $Exe -ArgumentList $ArgumentList -WindowStyle Hidden -RedirectStandardOutput $outFile -RedirectStandardError $errFile -PassThru
|
||||
# Windows PowerShell 5.1 returns a blank ExitCode unless the handle is read first.
|
||||
$null = $proc.Handle
|
||||
$finished = $proc.WaitForExit(1800000)
|
||||
if (-not $finished) {
|
||||
try { Stop-Process -Id $proc.Id -Force -ErrorAction SilentlyContinue } catch {}
|
||||
@@ -152,7 +154,10 @@ try {
|
||||
$env:SSH_ASKPASS_REQUIRE = 'force'
|
||||
$env:DISPLAY = 'dummy'
|
||||
|
||||
# -v is required here: on the staging PC the hidden SSH run hangs without it and
|
||||
# finishes in about 8 seconds with it. It only adds lines to stderr.
|
||||
$sshOpts = @(
|
||||
'-v',
|
||||
'-o', 'PreferredAuthentications=password',
|
||||
'-o', 'PubkeyAuthentication=no',
|
||||
'-o', 'NumberOfPasswordPrompts=1',
|
||||
@@ -163,9 +168,9 @@ $sshOpts = @(
|
||||
|
||||
Write-Log 'Starting copy from production.'
|
||||
|
||||
$list = Invoke-OpenSsh $ssh ($sshOpts + @($Remote, "ls -1 $RemoteDir/*.dump 2>/dev/null"))
|
||||
$list = Invoke-OpenSsh $ssh ($sshOpts + @($Remote, "ls $RemoteDir/*.dump 2>/dev/null"))
|
||||
if ($list.Code -ne 0 -and [string]::IsNullOrWhiteSpace($list.Out)) {
|
||||
$detail = $list.Err
|
||||
$detail = (($list.Err -split '\r?\n') | Select-Object -Last 3) -join ' | '
|
||||
if ([string]::IsNullOrWhiteSpace($detail)) {
|
||||
$detail = "ssh exit $($list.Code)"
|
||||
}
|
||||
@@ -220,7 +225,7 @@ foreach ($remotePath in $remoteFiles) {
|
||||
if (Test-Path -LiteralPath $partial) {
|
||||
Remove-Item -LiteralPath $partial -Force
|
||||
}
|
||||
$detail = $copied.Err
|
||||
$detail = (($copied.Err -split '\r?\n') | Select-Object -Last 3) -join ' | '
|
||||
if ([string]::IsNullOrWhiteSpace($detail)) {
|
||||
$detail = "scp exit $($copied.Code)"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user