clone-backup: ship the nc listener as a script file - inline bash -c quoting cannot carry --transform expressions

The slowdisk --transform args contain '|' and quotes; the ssh+screen+bash -c
stack strips one quoting level too many and splits the pipeline (broke the
katana retry within minutes of fccf2792). A heredoc-generated
/tmp/transfer_<key>.sh is parsed exactly once on the target. Applies to both
the screen and nohup listener branches; the direct-ssh fallback already had a
single shell layer and stays inline.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
rob
2026-07-11 02:21:34 +00:00
parent fccf279262
commit 9898af951a

View File

@@ -373,15 +373,17 @@ transfer_backup() {
if $SSH_CMD "$DEST_HOST" "which screen" >/dev/null 2>&1; then if $SSH_CMD "$DEST_HOST" "which screen" >/dev/null 2>&1; then
echo "Starting screen listener on port $port..." echo "Starting screen listener on port $port..."
# Start listener in screen session with proper escaping # Ship the listener as a SCRIPT FILE. tar_extract_opts can contain quoted
# The backup file is already zstd compressed, so we just decompress and extract # --transform expressions with '|' which inline bash -c quoting cannot
# Use tar_extract_opts which may include --skip-old-files for SLOWDISK mode # survive across the ssh+screen layers (broke the katana retry,
$SSH_CMD "$DEST_HOST" " # 2026-07-11). The heredoc expands locally; the target parses the script
screen -dmS transfer_${key} bash -c ' # exactly once.
$SSH_CMD "$DEST_HOST" "cat > /tmp/transfer_${key}.sh && chmod +x /tmp/transfer_${key}.sh" <<LISTENER
#!/bin/bash
nc -l -p $port | zstd -d | tar $tar_extract_opts 2>/tmp/transfer_${key}.err nc -l -p $port | zstd -d | tar $tar_extract_opts 2>/tmp/transfer_${key}.err
echo \$? > /tmp/transfer_${key}.done echo \$? > /tmp/transfer_${key}.done
' LISTENER
" $SSH_CMD "$DEST_HOST" "screen -dmS transfer_${key} /tmp/transfer_${key}.sh"
# Give it time to start # Give it time to start
sleep 2 sleep 2
@@ -395,15 +397,13 @@ transfer_backup() {
else else
echo "Screen not available, using nohup method..." echo "Screen not available, using nohup method..."
# Use nohup with proper backgrounding # Script-file listener for the same quoting reason as the screen branch.
# Use tar_extract_opts which may include --skip-old-files for SLOWDISK mode $SSH_CMD "$DEST_HOST" "cat > /tmp/transfer_${key}.sh && chmod +x /tmp/transfer_${key}.sh" <<LISTENER
$SSH_CMD "$DEST_HOST" " #!/bin/bash
nohup bash -c '
nc -l -p $port | zstd -d | tar $tar_extract_opts 2>/tmp/transfer_${key}.err nc -l -p $port | zstd -d | tar $tar_extract_opts 2>/tmp/transfer_${key}.err
echo \$? > /tmp/transfer_${key}.done echo \$? > /tmp/transfer_${key}.done
' > /tmp/transfer_${key}.log 2>&1 < /dev/null & LISTENER
echo \$! > /tmp/transfer_${key}.pid $SSH_CMD "$DEST_HOST" "nohup /tmp/transfer_${key}.sh > /tmp/transfer_${key}.log 2>&1 < /dev/null & echo \$! > /tmp/transfer_${key}.pid"
"
sleep 2 sleep 2