CMM: Backup-CMM defaults to S: record-retention path + prompts for CMM#

Default output is now S:\2 WJ Scans Record Retention\backup\cmm\<CmmId>\ instead
of C:\Logs. If S: is not mapped/reachable it falls back to C:\Logs\CMM\cmm-backup
so the backup still runs. When -CmmId is not passed the script prompts for it
(loops until non-empty) since it names the per-bay folder.

Smoke tested on the win11 VM: S: fallback path + the Read-Host prompt (fed via
redirected stdin) both produce the correctly-named per-CMM folder.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
cproudlock
2026-06-12 15:34:10 -04:00
parent f49fa0f940
commit 59deaea714

View File

@@ -11,23 +11,43 @@ restored by CMM machine-# at imaging.
Run as ADMINISTRATOR on the live CMM. Do NOT run on DODA bays (handled separately).
Output: C:\Logs\CMM\cmm-backup\<CmmId>\
Output (default): S:\2 WJ Scans Record Retention\backup\cmm\<CmmId>\
gocmm_backup_<PC>_<ts>.zip
pcdmis_backup_<PC>_<ver>_<ts>.zip (one per PC-DMIS version)
cmm-backup-index.json
If S: is not mapped/reachable, falls back to C:\Logs\CMM\cmm-backup\<CmmId>\.
Params:
-CmmId <id> e.g. CMM3 - names the folder + index (default: computer name)
-OutDir <p> base output folder (default C:\Logs\CMM\cmm-backup)
-CmmId <id> e.g. CMM3 - names the folder + index. If omitted, the script
PROMPTS for it.
-OutDir <p> base output folder (default the S: record-retention path above)
#>
param(
[string]$CmmId,
[string]$OutDir = 'C:\Logs\CMM\cmm-backup'
[string]$OutDir = 'S:\2 WJ Scans Record Retention\backup\cmm'
)
$ErrorActionPreference = 'Continue'
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$ts = Get-Date -Format 'yyyyMMdd-HHmmss'
if (-not $CmmId) { $CmmId = $env:COMPUTERNAME }
# Prompt for the CMM number if not passed. It names the backup folder, so we
# need a real value - loop until non-empty.
if (-not $CmmId) {
while (-not $CmmId) {
$CmmId = (Read-Host "Enter the CMM number for this bay (e.g. CMM3)").Trim()
if (-not $CmmId) { Write-Host " CMM number is required." -ForegroundColor Yellow }
}
}
# Default OutDir is on S: (record retention). If S: is not mapped or that base
# path is unreachable, fall back to a local folder so the backup still runs -
# the operator can copy it up to S: afterward.
$fallback = 'C:\Logs\CMM\cmm-backup'
$baseRoot = Split-Path -Qualifier $OutDir -ErrorAction SilentlyContinue
if ($baseRoot -and -not (Test-Path "$baseRoot\")) {
Write-Host "WARNING: $baseRoot is not reachable (S: not mapped?). Falling back to $fallback" -ForegroundColor Yellow
$OutDir = $fallback
}
$dest = Join-Path $OutDir $CmmId
New-Item -ItemType Directory -Path $dest -Force -ErrorAction SilentlyContinue | Out-Null
$log = Join-Path $dest "cmm-backup-$ts.log"