CHAT_OUTPUT_BEGIN
COMMAND_ID=HOMELAB-VM-2CLOUD-SELECTION-LOGIC-437
STATUS=OK
RC=0
HOST=pve01
MODE=read-only
COMPONENT=cluster-audit
REFERENCE_REGISTER_CHECK=OK
REFERENCE_SHA256=5763f2f8edc75fcf6f3951f8c95896d1cc112ceccb6cf5b64a383f540a4deb8e
ERROR_REGISTER_CHECK=OK
ERROR_REGISTER_SHA256=08b3a769b8e38eaa1acec915352fb328180d70caa7ff6cd9d1ec0da426262752
COMMAND_SHA256=ad4b5c1c52b4eaffa790b5ebe2bda18624ef1905c2e4259c94c24b9c7d9c1165
DUPLICATE_FAILED_COMMAND_BLOCKED=false
EXECUTION_STARTED=true
CHANGES_MADE=false
SANITIZED=yes
SECRETS_INCLUDED=no
PRIVATE_ADDRESSES_INCLUDED=no
RAW_EVIDENCE_SHA256=51b679ab8afb22764728c1e4338d954989e990db1de09b0c0e331ebc32674a6a
SANITIZED_OUTPUT_SHA256=51b679ab8afb22764728c1e4338d954989e990db1de09b0c0e331ebc32674a6a
OUTPUT_BEGIN
DETAIL=RUNTIME_SHA256=0ded6ba72e49b9cf7522c7f3d8840cc1026d2a173d4909dd3b4cfc5ff8831115
DETAIL=DESIRED_SHA256=0ded6ba72e49b9cf7522c7f3d8840cc1026d2a173d4909dd3b4cfc5ff8831115
DETAIL=SELECTION_SOURCE_BEGIN
DETAIL=SOURCE_LINE=0021:VMIDS="${VMIDS:-110 112 150}"
DETAIL=SOURCE_LINE=0022:
DETAIL=SOURCE_LINE=0023:source /etc/homelab-backup.env 2>/dev/null || BAD=1
DETAIL=SOURCE_LINE=0024:
DETAIL=SOURCE_LINE=0025:JOB_ID="homelab-${NODE}-vm-local-dumps-${JOB_TS}"
DETAIL=SOURCE_LINE=0026:WORK="$ROOT/$JOB_ID"
DETAIL=SOURCE_LINE=0027:mkdir -p "$WORK"
DETAIL=SOURCE_LINE=0028:
DETAIL=SOURCE_LINE=0029:FILES_TSV="$WORK/files.tsv"
DETAIL=SOURCE_LINE=0030:CHKS="$WORK/checksums.txt"
DETAIL=SOURCE_LINE=0031:MAN="$WORK/manifest.json"
DETAIL=SOURCE_LINE=0032:
DETAIL=SOURCE_LINE=0033:: > "$FILES_TSV"
DETAIL=SOURCE_LINE=0034:: > "$CHKS"
DETAIL=SOURCE_LINE=0035:: > "$LOG"
DETAIL=SOURCE_LINE=0036:
DETAIL=SOURCE_LINE=0037:echo "job_id=$JOB_ID" >> "$LOG"
DETAIL=SOURCE_LINE=0038:echo "vmids=$VMIDS" >> "$LOG"
DETAIL=SOURCE_LINE=0039:echo "chunk_size_bytes=$CHUNK_SIZE_BYTES" >> "$LOG"
DETAIL=SOURCE_LINE=0040:
DETAIL=SOURCE_LINE=0041:for id in $VMIDS; do
DETAIL=SOURCE_LINE=0042:  F="$(find /var/lib/vz/dump -maxdepth 1 -type f \( -name "vzdump-qemu-${id}-*.vma.zst" -o -name "vzdump-lxc-${id}-*.tar.zst" \) -printf "%T@ %p\n" 2>/dev/null | sort -n | tail -n 1 | cut -d" " -f2-)"
DETAIL=SOURCE_LINE=0043:  if [ -z "$F" ] || [ ! -f "$F" ]; then
DETAIL=SOURCE_LINE=0044:    echo "MISSING vmid=$id" >> "$LOG"
DETAIL=SOURCE_LINE=0045:    BAD=$((BAD+1))
DETAIL=SOURCE_LINE=0046:    continue
DETAIL=SOURCE_LINE=0047:  fi
DETAIL=SOURCE_LINE=0048:
DETAIL=SOURCE_LINE=0049:  BN="$(basename "$F")"
DETAIL=SOURCE_LINE=0050:  SIZE="$(stat -c %s "$F" 2>/dev/null || echo 0)"
DETAIL=SOURCE_LINE=0051:  MT="$(date -u -d "@$(stat -c %Y "$F" 2>/dev/null || echo 0)" +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || echo unknown)"
DETAIL=SOURCE_LINE=0052:  KIND="unknown"
DETAIL=SOURCE_LINE=0053:  echo "$BN" | grep -q "^vzdump-qemu-" && KIND="qemu"
DETAIL=SOURCE_LINE=0054:  echo "$BN" | grep -q "^vzdump-lxc-" && KIND="lxc"
DETAIL=SOURCE_LINE=0055:  SHA="$(sha256sum "$F" | cut -d" " -f1)"
DETAIL=SOURCE_LINE=0056:  printf "%s  %s\n" "$SHA" "$BN" >> "$CHKS"
DETAIL=SOURCE_LINE=0057:
DETAIL=SOURCE_LINE=0058:  MODE="direct"
DETAIL=SOURCE_LINE=0059:  PARTS=0
DETAIL=SOURCE_LINE=0060:  if [ "$SIZE" -gt "$CHUNK_SIZE_BYTES" ]; then
DETAIL=SOURCE_LINE=0061:    MODE="chunked"
DETAIL=SOURCE_LINE=0062:    CHUNKED=$((CHUNKED+1))
DETAIL=SOURCE_LINE=0063:    CDIR="$CHUNK_ROOT/$JOB_ID/$BN.chunks"
DETAIL=SOURCE_LINE=0064:    rm -rf "$CDIR"
DETAIL=SOURCE_LINE=0065:    mkdir -p "$CDIR"
DETAIL=SOURCE_LINE=0066:    echo "SPLIT file=$BN size=$SIZE chunk_size=$CHUNK_SIZE_SPLIT dir=$CDIR" >> "$LOG"
DETAIL=SOURCE_LINE=0067:    split -b "$CHUNK_SIZE_SPLIT" -d -a 4 "$F" "$CDIR/part-" >> "$LOG" 2>&1
DETAIL=SOURCE_LINE=0068:    PARTS="$(find "$CDIR" -maxdepth 1 -type f -name 'part-*' | wc -l)"
DETAIL=SOURCE_LINE=0069:    (cd "$CDIR" && sha256sum part-* > chunks.sha256)
DETAIL=SOURCE_LINE=0070:    if [ "$PARTS" -le 0 ]; then
DETAIL=SOURCE_LINE=0071:      echo "BAD split produced no chunks file=$BN" >> "$LOG"
DETAIL=SOURCE_LINE=0072:      BAD=$((BAD+1))
DETAIL=SOURCE_LINE=0073:    fi
DETAIL=SOURCE_LINE=0074:  fi
DETAIL=SOURCE_LINE=0075:
DETAIL=SOURCE_LINE=0076:  printf "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n" "$id" "$KIND" "$SIZE" "$SHA" "$MT" "$BN" "$F" "$MODE" "$PARTS" >> "$FILES_TSV"
DETAIL=SOURCE_LINE=0077:  COUNT=$((COUNT+1))
DETAIL=SOURCE_LINE=0078:  TOTAL=$((TOTAL+SIZE))
DETAIL=SOURCE_LINE=0079:done
DETAIL=SOURCE_LINE=0080:
DETAIL=SOURCE_LINE=0081:python3 - "$JOB_ID" "$NODE" "$TS" "$VMIDS" "$COUNT" "$TOTAL" "$CHUNKED" "$CHUNK_SIZE_BYTES" "$FILES_TSV" > "$MAN" <<'PY'
DETAIL=SOURCE_LINE=0082:import json, sys, pathlib
DETAIL=SOURCE_LINE=0083:job,node,ts,vmids,count,total,chunked,chunk_size,tsv=sys.argv[1:]
DETAIL=SOURCE_LINE=0084:items=[]
DETAIL=SOURCE_LINE=0085:for line in pathlib.Path(tsv).read_text().splitlines():
DETAIL=SOURCE_LINE=0086:    p=line.split("\t")
DETAIL=SOURCE_LINE=0087:    if len(p)>=9:
DETAIL=SOURCE_LINE=0088:        items.append({
DETAIL=SOURCE_LINE=0089:            "vmid":p[0],
DETAIL=SOURCE_LINE=0090:            "kind":p[1],
DETAIL=SOURCE_LINE=0091:            "size_bytes":int(p[2]),
DETAIL=SOURCE_LINE=...
DETAIL=SOURCE_LINE=0117:  rclone mkdir "$DEST/files" >> "$LOG" 2>&1 || BAD=$((BAD+1))
DETAIL=SOURCE_LINE=0118:  while IFS="$(printf "\t")" read -r id kind size sha mt bn path mode parts; do
DETAIL=SOURCE_LINE=0119:    if [ "$mode" = "chunked" ]; then
DETAIL=SOURCE_LINE=0120:      CDIR="$CHUNK_ROOT/$JOB_ID/$bn.chunks"
DETAIL=SOURCE_LINE=0121:      echo "UPLOAD_CHUNKED dest=$DEST file=$bn size=$size parts=$parts" >> "$LOG"
DETAIL=SOURCE_LINE=0122:      rclone mkdir "$DEST/files/$bn.chunks" >> "$LOG" 2>&1 || BAD=$((BAD+1))
DETAIL=SOURCE_LINE=0123:      for part in "$CDIR"/part-*; do
DETAIL=SOURCE_LINE=0124:        [ -f "$part" ] || continue
DETAIL=SOURCE_LINE=0125:        pn="$(basename "$part")"
DETAIL=SOURCE_LINE=0126:        rclone copyto "$part" "$DEST/files/$bn.chunks/$pn" --transfers 1 --checkers 4 >> "$LOG" 2>&1 || BAD=$((BAD+1))
DETAIL=SOURCE_LINE=0127:      done
DETAIL=SOURCE_LINE=0128:      rclone copyto "$CDIR/chunks.sha256" "$DEST/files/$bn.chunks/chunks.sha256" >> "$LOG" 2>&1 || BAD=$((BAD+1))
DETAIL=SOURCE_LINE=0129:    else
DETAIL=SOURCE_LINE=0130:      echo "UPLOAD_DIRECT dest=$DEST file=$bn size=$size" >> "$LOG"
DETAIL=SOURCE_LINE=0131:      rclone copyto "$path" "$DEST/files/$bn" --transfers 1 --checkers 4 >> "$LOG" 2>&1 || BAD=$((BAD+1))
DETAIL=SOURCE_LINE=0132:    fi
DETAIL=SOURCE_LINE=0133:  done < "$FILES_TSV"
DETAIL=SOURCE_LINE=0134:
DETAIL=SOURCE_LINE=0135:  rclone copyto "$CHKS" "$DEST/checksums.txt" >> "$LOG" 2>&1 || BAD=$((BAD+1))
DETAIL=SOURCE_LINE=0136:  rclone copyto "$FILES_TSV" "$DEST/files.tsv" >> "$LOG" 2>&1 || BAD=$((BAD+1))
DETAIL=SOURCE_LINE=0137:  rclone copyto "$MAN" "$DEST/manifest.json" >> "$LOG" 2>&1 || BAD=$((BAD+1))
DETAIL=SOURCE_LINE=0138:}
DETAIL=SOURCE_LINE=0139:
DETAIL=SOURCE_LINE=0140:verify_one_dest() {
DETAIL=SOURCE_LINE=0141:  LABEL="$1"
DETAIL=SOURCE_LINE=0142:  DEST="$2"
DETAIL=SOURCE_LINE=0143:  VBASE="$VERIFY_ROOT/$JOB_ID/$LABEL"
DETAIL=SOURCE_LINE=0144:  rm -rf "$VBASE"
DETAIL=SOURCE_LINE=0145:  mkdir -p "$VBASE"
DETAIL=SOURCE_LINE=0146:  rclone copyto "$DEST/manifest.json" "$VBASE/manifest.json" >> "$LOG" 2>&1 || BAD=$((BAD+1))
DETAIL=SOURCE_LINE=0147:  test -s "$VBASE/manifest.json" || BAD=$((BAD+1))
DETAIL=SOURCE_LINE=0148:
DETAIL=SOURCE_LINE=0149:  while IFS="$(printf "\t")" read -r id kind size sha mt bn path mode parts; do
DETAIL=SOURCE_LINE=0150:    if [ "$mode" = "chunked" ]; then
DETAIL=SOURCE_LINE=0151:      VDIR="$VBASE/$bn.chunks"
DETAIL=SOURCE_LINE=0152:      mkdir -p "$VDIR"
DETAIL=SOURCE_LINE=0153:      echo "VERIFY_CHUNKED label=$LABEL file=$bn parts=$parts" >> "$LOG"
DETAIL=SOURCE_LINE=0154:      rclone copy "$DEST/files/$bn.chunks" "$VDIR" --filter "+ part-*" --filter "+ chunks.sha256" --filter "- *" --transfers 1 --checkers 4 >> "$LOG" 2>&1 || BAD=$((BAD+1))
DETAIL=SOURCE_LINE=0155:      (cd "$VDIR" && sha256sum -c chunks.sha256) >> "$LOG" 2>&1 || BAD=$((BAD+1))
DETAIL=SOURCE_LINE=0156:      CALC="$(find "$VDIR" -maxdepth 1 -type f -name 'part-*' | sort | xargs cat | sha256sum | cut -d" " -f1)"
DETAIL=SOURCE_LINE=0157:      if [ "$CALC" = "$sha" ]; then
DETAIL=SOURCE_LINE=0158:        echo "OK combined_sha label=$LABEL file=$bn sha=$sha" >> "$LOG"
DETAIL=SOURCE_LINE=0159:      else
DETAIL=SOURCE_LINE=0160:        echo "BAD combined_sha label=$LABEL file=$bn expected=$sha got=$CALC" >> "$LOG"
DETAIL=SOURCE_LINE=0161:        BAD=$((BAD+1))
DETAIL=SOURCE_LINE=0162:      fi
DETAIL=SOURCE_LINE=0163:      rm -rf "$VDIR"
DETAIL=SOURCE_LINE=0164:    else
DETAIL=SOURCE_LINE=0165:      echo "VERIFY_DIRECT label=$LABEL file=$bn" >> "$LOG"
DETAIL=SOURCE_LINE=0166:      rclone copyto "$DEST/files/$bn" "$VBASE/$bn" --transfers 1 >> "$LOG" 2>&1 || BAD=$((BAD+1))
DETAIL=SOURCE_LINE=0167:      printf "%s  %s\n" "$sha" "$VBASE/$bn" | sha256sum -c - >> "$LOG" 2>&1 || BAD=$((BAD+1))
DETAIL=SOURCE_LINE=0168:      rm -f "$VBASE/$bn"
DETAIL=SOURCE_LINE=0169:    fi
DETAIL=SOURCE_LINE=0170:  done < "$FILES_TSV"
DETAIL=SOURCE_LINE=0171:  rm -rf "$VBASE"
DETAIL=SOURCE_LINE=0172:}
DETAIL=SOURCE_LINE=0173:
DETAIL=SOURCE_LINE=0174:if [ "$BAD" -eq 0 ]; then
DETAIL=SOURCE_LINE=0175:  upload_one_dest "$DEST_A"
DETAIL=SOURCE_LINE=0176:  upload_one_dest "$DEST_B"
DETAIL=SOURCE_LINE=0177:fi
DETAIL=SOURCE_LINE=0178:
DETAIL=SOURCE_LINE=0179:if [ "$BAD" -eq 0 ]; then
DETAIL=SOURCE_LINE=0180:  verify_one_dest "A" "$DEST_A"
DETAIL=SOURCE_LINE=...
DETAIL=SOURCE_LINE=0198:        ;;
DETAIL=SOURCE_LINE=0199:      *)
DETAIL=SOURCE_LINE=0200:        echo "REFUSE_DELETE_OUTSIDE_ALLOWED_ROOT path=$path" >> "$LOG"
DETAIL=SOURCE_LINE=0201:        BAD=$((BAD+1))
DETAIL=SOURCE_LINE=0202:        continue
DETAIL=SOURCE_LINE=0203:        ;;
DETAIL=SOURCE_LINE=0204:    esac
DETAIL=SOURCE_LINE=0205:
DETAIL=SOURCE_LINE=0206:    if [ "$(basename "$path")" != "$bn" ]; then
DETAIL=SOURCE_LINE=0207:      echo "REFUSE_DELETE_BASENAME_MISMATCH path=$path expected=$bn" >> "$LOG"
DETAIL=SOURCE_LINE=0208:      BAD=$((BAD+1))
DETAIL=SOURCE_LINE=0209:      continue
DETAIL=SOURCE_LINE=0210:    fi
DETAIL=SOURCE_LINE=0211:
DETAIL=SOURCE_LINE=0212:    if [ ! -f "$path" ] || [ -L "$path" ]; then
DETAIL=SOURCE_LINE=0213:      echo "REFUSE_DELETE_INVALID_SOURCE path=$path" >> "$LOG"
DETAIL=SOURCE_LINE=0214:      BAD=$((BAD+1))
DETAIL=SOURCE_LINE=0215:      continue
DETAIL=SOURCE_LINE=0216:    fi
DETAIL=SOURCE_LINE=0217:
DETAIL=SOURCE_LINE=0218:    actual_size="$(stat -c %s "$path" 2>/dev/null || echo 0)"
DETAIL=SOURCE_LINE=0219:
DETAIL=SOURCE_LINE=0220:    if [ "$actual_size" != "$size" ]; then
DETAIL=SOURCE_LINE=0221:      echo "REFUSE_DELETE_SIZE_MISMATCH path=$path expected=$size actual=$actual_size" >> "$LOG"
DETAIL=SOURCE_LINE=0222:      BAD=$((BAD+1))
DETAIL=SOURCE_LINE=0223:      continue
DETAIL=SOURCE_LINE=0224:    fi
DETAIL=SOURCE_LINE=0225:
DETAIL=SOURCE_LINE=0226:    actual_sha="$(sha256sum "$path" 2>>"$LOG" | cut -d " " -f1 || true)"
DETAIL=SOURCE_LINE=0227:
DETAIL=SOURCE_LINE=0228:    if [ "$actual_sha" != "$sha" ]; then
DETAIL=SOURCE_LINE=0229:      echo "REFUSE_DELETE_SHA_MISMATCH path=$path" >> "$LOG"
DETAIL=SOURCE_LINE=0230:      BAD=$((BAD+1))
DETAIL=SOURCE_LINE=0231:      continue
DETAIL=SOURCE_LINE=0232:    fi
DETAIL=SOURCE_LINE=0233:
DETAIL=SOURCE_LINE=0234:    echo "PREDELETE_VALIDATION_OK path=$path size=$size sha=$sha" >> "$LOG"
DETAIL=SOURCE_LINE=0235:  done < "$FILES_TSV"
DETAIL=SOURCE_LINE=0236:
DETAIL=SOURCE_LINE=0237:  echo "PREDELETE_VALIDATION_END bad=$BAD" >> "$LOG"
DETAIL=SOURCE_LINE=0238:fi
DETAIL=SOURCE_LINE=0239:
DETAIL=SOURCE_LINE=0240:if [ "$BAD" -eq 0 ]; then
DETAIL=SOURCE_LINE=0241:  echo "LOCAL_PAYLOAD_DELETE_BEGIN" >> "$LOG"
DETAIL=SOURCE_LINE=0242:
DETAIL=SOURCE_LINE=0243:  while IFS="$(printf "	")" read -r id kind size sha mt bn path mode parts; do
DETAIL=SOURCE_LINE=0244:    if rm -f -- "$path" 2>>"$LOG"; then
DETAIL=SOURCE_LINE=0245:      if [ ! -e "$path" ] && [ ! -L "$path" ]; then
DETAIL=SOURCE_LINE=...
DETAIL=SOURCE_LINE=0249:      else
DETAIL=SOURCE_LINE=0250:        echo "LOCAL_PAYLOAD_DELETE_CONFIRM_FAILED path=$path" >> "$LOG"
DETAIL=SOURCE_LINE=0251:        BAD=$((BAD+1))
DETAIL=SOURCE_LINE=0252:      fi
DETAIL=SOURCE_LINE=0253:    else
DETAIL=SOURCE_LINE=0254:      echo "LOCAL_PAYLOAD_DELETE_FAILED path=$path" >> "$LOG"
DETAIL=SOURCE_LINE=0255:      BAD=$((BAD+1))
DETAIL=SOURCE_LINE=0256:    fi
DETAIL=SOURCE_LINE=0257:  done < "$FILES_TSV"
DETAIL=SOURCE_LINE=0258:
DETAIL=SOURCE_LINE=0259:  if [ "$BAD" -eq 0 ] && [ "$DELETED_COUNT" -eq "$COUNT" ]; then
DETAIL=SOURCE_LINE=0260:    LOCAL_DUMPS_DELETED=true
DETAIL=SOURCE_LINE=0261:  fi
DETAIL=SOURCE_LINE=0262:
DETAIL=SOURCE_LINE=0263:  echo "LOCAL_PAYLOAD_DELETE_END deleted_count=$DELETED_COUNT deleted_bytes=$DELETED_BYTES bad=$BAD" >> "$LOG"
DETAIL=SOURCE_LINE=0264:fi
DETAIL=SOURCE_LINE=0265:
DETAIL=SOURCE_LINE=0266:if [ "$BAD" -eq 0 ] && [ "$LOCAL_DUMPS_DELETED" = true ]; then
DETAIL=SOURCE_LINE=0267:  STATUS="OK"
DETAIL=SELECTION_SOURCE_END
DETAIL=INVENTORY_GROUP_COUNT=3
DETAIL=INVENTORY_GROUP=KIND:lxc|ID:110|COUNT:4|TOTAL_BYTES:1337879243|LATEST_PATH:/var/lib/vz/dump/vzdump-lxc-110-2026_07_24-03_30_02.tar.zst|LATEST_BYTES:339140622
DETAIL=INVENTORY_GROUP=KIND:lxc|ID:112|COUNT:4|TOTAL_BYTES:891239268|LATEST_PATH:/var/lib/vz/dump/vzdump-lxc-112-2026_07_24-03_30_11.tar.zst|LATEST_BYTES:222859457
DETAIL=INVENTORY_GROUP=KIND:qemu|ID:150|COUNT:4|TOTAL_BYTES:28114919054|LATEST_PATH:/var/lib/vz/dump/vzdump-qemu-150-2026_07_24-03_30_16.vma.zst|LATEST_BYTES:7016624549
DETAIL=ALL_ARCHIVE_COUNT=12
DETAIL=ALL_ARCHIVE_BYTES=30344037565
DETAIL=LATEST_PER_OBJECT_COUNT=3
DETAIL=LATEST_PER_OBJECT_BYTES=7578624628
DETAIL=BACKUP_PAYLOAD_CHANGED=NO
DETAIL=SECRET_VALUES_OUTPUT=NONE
DETAIL=VM_2CLOUD_SELECTION_LOGIC_AUDIT=PASS
CHANGES_MADE=NO

OUTPUT_END
CHAT_OUTPUT_END
