Restore-CMM.ps1 (new) restores a CMM's PC-DMIS + goCMM settings at imaging from
its staged backup. Self-gating: reads C:\Enrollment\cmm\{cmmid,version,doda,
partgroup}.txt, skips DODA bays and bays with no staged backup, and restores
ONLY the config-version PC-DMIS zip via the existing Install-*Settings scripts.
Same-bay restore (cmmid match) so the backed-up controller CommPort is this
bay's own value - no cross-bay clobber.
Version selection matches the VERSION FIELD of the zip name, anchored on the
trailing timestamp, so version=2026 does not false-match a 2019/2016 zip whose
backup timestamp (20260612...) merely contains "2026".
09-Setup-CMM.ps1: new Step 2.8 calls Restore-CMM after app install + first-run
init (so a restored config is not clobbered by PC-DMIS defaults) and before the
C:\CMM-Install cleanup (the backup set lives under <stagingRoot>\backups\<cmmid>).
Best-effort: Restore-CMM always exits 0, imaging never fails on a restore.
startnet.cmd: stage ONLY the picked bay's backup into C:\CMM-Install\backups\
%CMMID% (the bulk robocopy now /XD-excludes the backups tree, which holds every
bay's backup - some 240 MB each - to avoid copying GBs to every imaged CMM).
Also bump the PPKG to v4.16 (the live boot.wim was already v4.16; the repo had
drifted to v4.14).
sync-cmm-backups.sh: source the backups from pxe-images/cmm/backups (where
Backup-CMM writes via the pulled-down copies), not the old cmm-bk path.
Smoke tested on the win11 VM against CMM3's real backup: version=2019 restored
the 2019 R2 zip (not 2016.0), imported HKLM+HKCU reg, converted the part-group
S:\ path to the tsgwp00525 UNC, created C:\geaofi, exit 0; version=2026 correctly
found no matching zip (anchor works).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
68 lines
3.2 KiB
Bash
Executable File
68 lines
3.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# sync-cmm-backups.sh - stage per-CMM backups (goCMM + PC-DMIS) on the PXE
|
|
# enrollment share so 09-Setup-CMM can restore them by CMM machine-# at imaging.
|
|
# (Distinct from sync-cmm.sh, which stages the CMM *installers* bundle.)
|
|
#
|
|
# Source layout - one folder per CMM, named by the cmm_id in cmm-bay-config.csv,
|
|
# produced by Backup-CMM.ps1 and mirrored here from the live bays:
|
|
# /home/camp/pxe-images/cmm/backups/<cmm_id>/
|
|
# gocmm_backup_<PC>_<ts>.zip
|
|
# pcdmis_backup_<PC>_<ver>_<ts>.zip (one per installed PC-DMIS version)
|
|
# cmm-backup-index.json
|
|
#
|
|
# Pushes the NEWEST backup set per cmm_id to:
|
|
# /srv/samba/enrollment/installers-post/cmm/backups/<cmm_id>/
|
|
#
|
|
# DODA bays: do NOT back them up (don't put them under cmm-bk/). 09-Setup-CMM
|
|
# also gates restore on cmm-bay-config doda=no as a second guard.
|
|
#
|
|
# Usage: ./playbook/sync-cmm-backups.sh (all cmm_id folders)
|
|
# CMM_ID=CMM3 ./playbook/sync-cmm-backups.sh (just one)
|
|
set -euo pipefail
|
|
|
|
PXE_HOST="${PXE_HOST:-172.16.9.1}"
|
|
PXE_USER="${PXE_USER:-pxe}"
|
|
PXE_PASS="${PXE_PASS:-pxe}"
|
|
BACKUP_SRC_DIR="${CMM_BACKUP_DIR:-/home/camp/pxe-images/cmm/backups}"
|
|
REMOTE_BASE="/srv/samba/enrollment/installers-post/cmm/backups"
|
|
ONLY_ID="${CMM_ID:-}"
|
|
|
|
ssh_run() { sshpass -p "$PXE_PASS" ssh -o StrictHostKeyChecking=no -o LogLevel=ERROR "$PXE_USER@$PXE_HOST" "$@"; }
|
|
scp_to() { sshpass -p "$PXE_PASS" scp -o StrictHostKeyChecking=no -o LogLevel=ERROR "$@"; }
|
|
|
|
command -v sshpass >/dev/null || { echo "sshpass required (apt install sshpass)"; exit 1; }
|
|
[ -d "$BACKUP_SRC_DIR" ] || { echo "No backup source dir: $BACKUP_SRC_DIR"; echo "Run Backup-CMM on the bays and mirror each cmm-backup\\<cmm_id>\\ folder here."; exit 1; }
|
|
ping -c1 -W2 "$PXE_HOST" >/dev/null 2>&1 || { echo "PXE host $PXE_HOST unreachable"; exit 1; }
|
|
|
|
count=0
|
|
for cmm_dir in "$BACKUP_SRC_DIR"/*/; do
|
|
[ -d "$cmm_dir" ] || continue
|
|
cmm_id="$(basename "$cmm_dir")"
|
|
[ -n "$ONLY_ID" ] && [ "$cmm_id" != "$ONLY_ID" ] && continue
|
|
|
|
# newest goCMM zip + every pcdmis zip (one per version) + the index
|
|
mapfile -t zips < <(ls -1t "$cmm_dir"/gocmm_backup_*.zip 2>/dev/null | head -1; \
|
|
ls -1t "$cmm_dir"/pcdmis_backup_*.zip 2>/dev/null)
|
|
if [ ${#zips[@]} -eq 0 ]; then echo " [$cmm_id] no backup zips - skipping"; continue; fi
|
|
|
|
echo "==> [$cmm_id] staging ${#zips[@]} zip(s)"
|
|
REMOTE_TMP="/tmp/cmm-bk-stage-$cmm_id-$$"
|
|
ssh_run "rm -rf '$REMOTE_TMP' && mkdir -p '$REMOTE_TMP'"
|
|
for z in "${zips[@]}"; do scp_to "$z" "$PXE_USER@$PXE_HOST:$REMOTE_TMP/"; done
|
|
[ -f "$cmm_dir/cmm-backup-index.json" ] && scp_to "$cmm_dir/cmm-backup-index.json" "$PXE_USER@$PXE_HOST:$REMOTE_TMP/"
|
|
|
|
# atomic swap into the share (root-owned -> sudo); keep a timestamped copy of the prior set
|
|
ssh_run "echo $PXE_PASS | sudo -S bash -c '
|
|
mkdir -p \"$REMOTE_BASE\"
|
|
dst=\"$REMOTE_BASE/$cmm_id\"
|
|
if [ -d \"\$dst\" ]; then mv \"\$dst\" \"\${dst}.pre-\$(date +%Y%m%d-%H%M%S)\"; fi
|
|
mv \"$REMOTE_TMP\" \"\$dst\"
|
|
chown -R pxe:pxe \"\$dst\"
|
|
ls -la \"\$dst\"
|
|
'"
|
|
count=$((count+1))
|
|
done
|
|
|
|
echo "==> Done. Staged $count CMM backup set(s) to $PXE_USER@$PXE_HOST:$REMOTE_BASE"
|
|
echo " 09-Setup-CMM restores <cmm_id> at imaging when that CMM is picked (and doda=no)."
|