Files
pxe-server/playbook/sync-cmm-backups.sh
cproudlock b5b644a360 CMM/DODA: restore on DODA bays + grant Full on whole C:\Apps\DODA
- Restore-CMM: drop the skip-on-doda gate. DODA bays now restore the
  config-version PC-DMIS + goCMM settings like any other bay (they have backups
  now; DODA itself installs separately to C:\Apps\DODA and is unaffected).
- sync-cmm-backups.sh: update the stale "do not back up DODA bays" note.
- Install-DODA.ps1: grant Users + Authenticated Users Full on the WHOLE
  C:\Apps\DODA (was PreProcess only) - DODA writes output/temp throughout the
  folder as the locked-down operator. /T covers PreProcess.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-17 17:22:06 -04:00

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 ARE backed up + restored like any other now (the old skip-on-doda
# policy in Restore-CMM was dropped 2026-06-17). Stage them here the same way.
#
# 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)."