Standard-Machine: UDC backup/restore use ArchivedData (not ArchiveData)

UDC's per-bay archive directory is C:\ProgramData\UDC\ArchivedData, not
ArchiveData. The previous spelling was a typo introduced when the scripts
were first written; it would have meant Backup-UDCData.ps1 found no archive
content (silent zero-file backups), and Restore-UDCData.ps1 wrote into a
location UDC does not read from.

Path swap is straight string replacement across both scripts plus the .bat
wrapper's usage comment. Manifest field names in backup.manifest.json /
restore.manifest.json (ArchivedDataPresent, ArchivedDataFiles,
ArchivedDataBytes) updated to match.

Update-MachineNumber.ps1's parallel UDC-restore branch (still uncommitted
in a prior workstream) has the same fix in the working tree, captured in
that branch's eventual commit.

The v2 share-staged copy at tsgwp00525-v2\standard-machine\scripts\
Restore-UDCData.ps1 also got the fix and is ready for push.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
cproudlock
2026-04-29 11:45:39 -04:00
parent 0badfc1983
commit e169f8d0f5
3 changed files with 22 additions and 22 deletions

View File

@@ -10,7 +10,7 @@ REM 1. Double-click Backup-UDCData.bat (or right-click -> Run as admin)
REM 2. Approve the UAC prompt REM 2. Approve the UAC prompt
REM 3. Watch the elevated PS window for the success summary REM 3. Watch the elevated PS window for the success summary
REM 4. Confirm \\tsgwp00525.wjs.geaerospace.net\shared\dt\shopfloor\backup\udc\<machine>\ REM 4. Confirm \\tsgwp00525.wjs.geaerospace.net\shared\dt\shopfloor\backup\udc\<machine>\
REM now contains CurrentData.json + ArchiveData\ + backup.manifest.json REM now contains CurrentData.json + ArchivedData\ + backup.manifest.json
REM --- Self-elevate --------------------------------------------------- REM --- Self-elevate ---------------------------------------------------
net session >nul 2>&1 net session >nul 2>&1

View File

@@ -1,4 +1,4 @@
# Backup-UDCData.ps1 - Capture UDC's CurrentData.json + ArchiveData/ to the # Backup-UDCData.ps1 - Capture UDC's CurrentData.json + ArchivedData/ to the
# SFLD share, keyed by the PC's current machine number. Runs LOCALLY on the # SFLD share, keyed by the PC's current machine number. Runs LOCALLY on the
# old PC before retirement; the new PC restores during its first # old PC before retirement; the new PC restores during its first
# placeholder-to-real machine-number assignment via Update-MachineNumber.ps1. # placeholder-to-real machine-number assignment via Update-MachineNumber.ps1.
@@ -88,18 +88,18 @@ Log "Resolved machine number: $MachineNumber"
# --- Verify source files exist --- # --- Verify source files exist ---
$srcCurrent = Join-Path $UdcDataDir 'CurrentData.json' $srcCurrent = Join-Path $UdcDataDir 'CurrentData.json'
$srcArchive = Join-Path $UdcDataDir 'ArchiveData' $srcArchive = Join-Path $UdcDataDir 'ArchivedData'
$haveCurrent = Test-Path -LiteralPath $srcCurrent $haveCurrent = Test-Path -LiteralPath $srcCurrent
$haveArchive = Test-Path -LiteralPath $srcArchive $haveArchive = Test-Path -LiteralPath $srcArchive
if (-not $haveCurrent -and -not $haveArchive) { if (-not $haveCurrent -and -not $haveArchive) {
Log "Neither CurrentData.json nor ArchiveData/ exists under $UdcDataDir. Nothing to back up." 'WARN' Log "Neither CurrentData.json nor ArchivedData/ exists under $UdcDataDir. Nothing to back up." 'WARN'
try { Stop-Transcript | Out-Null } catch {} try { Stop-Transcript | Out-Null } catch {}
exit 0 exit 0
} }
Log "CurrentData.json present: $haveCurrent" Log "CurrentData.json present: $haveCurrent"
Log "ArchiveData/ present: $haveArchive" Log "ArchivedData/ present: $haveArchive"
# --- Mount share if credentials supplied (otherwise rely on ambient auth) --- # --- Mount share if credentials supplied (otherwise rely on ambient auth) ---
$psDrive = $null $psDrive = $null
@@ -156,13 +156,13 @@ if ($haveCurrent) {
} }
} }
# --- Copy ArchiveData/ recursively --- # --- Copy ArchivedData/ recursively ---
$copiedArchive = $false $copiedArchive = $false
$archiveBytes = 0 $archiveBytes = 0
$archiveFiles = 0 $archiveFiles = 0
if ($haveArchive) { if ($haveArchive) {
try { try {
$destArchive = Join-Path $dest 'ArchiveData' $destArchive = Join-Path $dest 'ArchivedData'
if (Test-Path -LiteralPath $destArchive) { if (Test-Path -LiteralPath $destArchive) {
Remove-Item -LiteralPath $destArchive -Recurse -Force -ErrorAction Stop Remove-Item -LiteralPath $destArchive -Recurse -Force -ErrorAction Stop
} }
@@ -171,9 +171,9 @@ if ($haveArchive) {
$archiveItems = Get-ChildItem -LiteralPath $destArchive -Recurse -File -ErrorAction SilentlyContinue $archiveItems = Get-ChildItem -LiteralPath $destArchive -Recurse -File -ErrorAction SilentlyContinue
$archiveBytes = ($archiveItems | Measure-Object Length -Sum).Sum $archiveBytes = ($archiveItems | Measure-Object Length -Sum).Sum
$archiveFiles = $archiveItems.Count $archiveFiles = $archiveItems.Count
Log "Copied ArchiveData/ ($archiveFiles files, $archiveBytes bytes)" Log "Copied ArchivedData/ ($archiveFiles files, $archiveBytes bytes)"
} catch { } catch {
Log "Failed to copy ArchiveData/: $_" 'ERROR' Log "Failed to copy ArchivedData/: $_" 'ERROR'
} }
} }
@@ -186,9 +186,9 @@ try {
MachineNumber = $MachineNumber MachineNumber = $MachineNumber
CurrentDataPresent = $copiedCurrent CurrentDataPresent = $copiedCurrent
CurrentDataBytes = $currentBytes CurrentDataBytes = $currentBytes
ArchiveDataPresent = $copiedArchive ArchivedDataPresent = $copiedArchive
ArchiveDataFiles = $archiveFiles ArchivedDataFiles = $archiveFiles
ArchiveDataBytes = $archiveBytes ArchivedDataBytes = $archiveBytes
} }
$manifest | ConvertTo-Json | Set-Content -Path (Join-Path $dest 'backup.manifest.json') -Encoding UTF8 $manifest | ConvertTo-Json | Set-Content -Path (Join-Path $dest 'backup.manifest.json') -Encoding UTF8
Log "Wrote backup.manifest.json" Log "Wrote backup.manifest.json"
@@ -206,7 +206,7 @@ Log "Backup complete:"
Log " Bay: $MachineNumber" Log " Bay: $MachineNumber"
Log " Destination: $BackupShareRoot\$MachineNumber\" Log " Destination: $BackupShareRoot\$MachineNumber\"
Log " CurrentData.json: $(if ($copiedCurrent) {'OK ('+$currentBytes+' bytes)'} else {'MISSING'})" Log " CurrentData.json: $(if ($copiedCurrent) {'OK ('+$currentBytes+' bytes)'} else {'MISSING'})"
Log " ArchiveData/: $(if ($copiedArchive) {'OK ('+$archiveFiles+' files, '+$archiveBytes+' bytes)'} else {'MISSING'})" Log " ArchivedData/: $(if ($copiedArchive) {'OK ('+$archiveFiles+' files, '+$archiveBytes+' bytes)'} else {'MISSING'})"
Log "===============================================" Log "==============================================="
try { Stop-Transcript | Out-Null } catch {} try { Stop-Transcript | Out-Null } catch {}
exit 0 exit 0

View File

@@ -8,7 +8,7 @@
# CONTRACT: # CONTRACT:
# - 99% of cycles: no backup waiting -> exit 0 in ~1 second, no side effects # - 99% of cycles: no backup waiting -> exit 0 in ~1 second, no side effects
# - 1 cycle (the one after Backup-UDCData lands a backup for this PC's bay): # - 1 cycle (the one after Backup-UDCData lands a backup for this PC's bay):
# stop UDC, copy CurrentData.json + ArchiveData/ to C:\ProgramData\UDC, # stop UDC, copy CurrentData.json + ArchivedData/ to C:\ProgramData\UDC,
# move consumed backup to <bay>\migrated\<timestamp>\, write # move consumed backup to <bay>\migrated\<timestamp>\, write
# restore.manifest.json, restart UDC. After this, root is empty so the # restore.manifest.json, restart UDC. After this, root is empty so the
# check returns "no backup waiting" again on subsequent cycles. # check returns "no backup waiting" again on subsequent cycles.
@@ -71,7 +71,7 @@ if (-not $mn -or $mn -eq '9999' -or $mn -notmatch '^\d+$') {
# --- Probe for a waiting backup --- # --- Probe for a waiting backup ---
$bayDir = Join-Path $BackupShareRoot $mn $bayDir = Join-Path $BackupShareRoot $mn
$srcCur = Join-Path $bayDir 'CurrentData.json' $srcCur = Join-Path $bayDir 'CurrentData.json'
$srcArc = Join-Path $bayDir 'ArchiveData' $srcArc = Join-Path $bayDir 'ArchivedData'
if (-not (Test-Path -LiteralPath $srcCur)) { if (-not (Test-Path -LiteralPath $srcCur)) {
# Most-common path: no backup waiting. Exit silently to keep enforce-cycle # Most-common path: no backup waiting. Exit silently to keep enforce-cycle
@@ -102,7 +102,7 @@ if (-not (Test-Path -LiteralPath $UdcDataDir)) {
New-Item -ItemType Directory -Path $UdcDataDir -Force | Out-Null New-Item -ItemType Directory -Path $UdcDataDir -Force | Out-Null
} }
$localCur = Join-Path $UdcDataDir 'CurrentData.json' $localCur = Join-Path $UdcDataDir 'CurrentData.json'
$localArc = Join-Path $UdcDataDir 'ArchiveData' $localArc = Join-Path $UdcDataDir 'ArchivedData'
# --- Copy CurrentData.json --- # --- Copy CurrentData.json ---
$copiedCur = $false $copiedCur = $false
@@ -114,7 +114,7 @@ try {
Log "Copy CurrentData.json failed: $_" 'ERROR' Log "Copy CurrentData.json failed: $_" 'ERROR'
} }
# --- Copy ArchiveData/ --- # --- Copy ArchivedData/ ---
$copiedArc = $false $copiedArc = $false
$arcFiles = 0 $arcFiles = 0
$arcBytes = 0 $arcBytes = 0
@@ -128,9 +128,9 @@ if (Test-Path -LiteralPath $srcArc) {
$arcFiles = $arcItems.Count $arcFiles = $arcItems.Count
$arcBytes = ($arcItems | Measure-Object Length -Sum).Sum $arcBytes = ($arcItems | Measure-Object Length -Sum).Sum
$copiedArc = $true $copiedArc = $true
Log "Copied ArchiveData/ ($arcFiles files, $arcBytes bytes)" Log "Copied ArchivedData/ ($arcFiles files, $arcBytes bytes)"
} catch { } catch {
Log "Copy ArchiveData/ failed: $_" 'ERROR' Log "Copy ArchivedData/ failed: $_" 'ERROR'
} }
} }
@@ -147,7 +147,7 @@ if ($consumeOk) {
Move-Item -LiteralPath $srcCur -Destination (Join-Path $migStamp 'CurrentData.json') -Force -ErrorAction Stop Move-Item -LiteralPath $srcCur -Destination (Join-Path $migStamp 'CurrentData.json') -Force -ErrorAction Stop
if (Test-Path -LiteralPath $srcArc) { if (Test-Path -LiteralPath $srcArc) {
Move-Item -LiteralPath $srcArc -Destination (Join-Path $migStamp 'ArchiveData') -Force -ErrorAction Stop Move-Item -LiteralPath $srcArc -Destination (Join-Path $migStamp 'ArchivedData') -Force -ErrorAction Stop
} }
$bakManifest = Join-Path $bayDir 'backup.manifest.json' $bakManifest = Join-Path $bayDir 'backup.manifest.json'
if (Test-Path -LiteralPath $bakManifest) { if (Test-Path -LiteralPath $bakManifest) {
@@ -160,8 +160,8 @@ if ($consumeOk) {
DestinationUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name DestinationUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
MachineNumber = $mn MachineNumber = $mn
CurrentDataBytes = (Get-Item $localCur).Length CurrentDataBytes = (Get-Item $localCur).Length
ArchiveDataFiles = $arcFiles ArchivedDataFiles = $arcFiles
ArchiveDataBytes = $arcBytes ArchivedDataBytes = $arcBytes
RestoredVia = 'Restore-UDCData.ps1 (manifest engine, on logon)' RestoredVia = 'Restore-UDCData.ps1 (manifest engine, on logon)'
} }
$restoreManifest | ConvertTo-Json | Set-Content -Path (Join-Path $migStamp 'restore.manifest.json') -Encoding UTF8 $restoreManifest | ConvertTo-Json | Set-Content -Path (Join-Path $migStamp 'restore.manifest.json') -Encoding UTF8