#!/bin/bash
# IT813549 - root no sp1-sd-inovatech-4. LV da 2379 (desligada) -> zstd -> ssh -> /dev/vdd no IT089947-HELPER.
set -u
H=177.85.38.42; K=/root/.ssh/wci-dep; L=/mnt/pve/NFS01/migrate/IT813549/logs; mkdir -p $L
[ "$(qm status 2379 | awk '{print $2}')" = stopped ] || { echo "ABORT: 2379 nao esta stopped"; exit 1; }
LV=$(pvesm path Storage0:vm-2379-disk-0); lvchange -ay "$LV" 2>/dev/null
echo "$(date +%T) INICIO $LV ($(blockdev --getsize64 $LV) bytes)"
t0=$SECONDS
dd if="$LV" bs=4M status=none | zstd -1 -T8 -q | ssh -i $K -c aes128-gcm@openssh.com -o Compression=no \
  -o StrictHostKeyChecking=no -o BatchMode=yes -o ServerAliveInterval=30 ubuntu@$H \
  "unzstd | sudo dd of=/dev/vdd bs=4M conv=sparse status=none && sudo sync && echo DESTINO_OK"
echo "$(date +%T) rc=[${PIPESTATUS[*]}] $((SECONDS-t0))s"
echo "$(date +%T) TODAS_AS_COPIAS_FIM"
