#!/bin/bash # 带校验重试的接力搬运:47:/tmp/-* --(并行拉+大小校验+重拉)--> 本机 --高速--> 106 --> (可选)解包 # 用法: _relay2.sh [解包目标目录] export PATH="/d/Program Files/Git/usr/bin:/c/Windows/System32:/c/Windows:$PATH" SSH="ssh -o BatchMode=yes -o ConnectTimeout=15" SCP="scp -q -o BatchMode=yes -o ConnectTimeout=15" P="$1"; N="$2"; DEST="$3" L="/e/ProgramData/AIProject/ai1net-dsh-server/_relay-$N" mkdir -p "$L" $SSH bt-server "stat -c '%s %n' /tmp/$P-*" > "$L/remote.txt" TOTAL=$(wc -l < "$L/remote.txt") echo "远端分片=$TOTAL" for round in 1 2 3; do : > "$L/redo.txt" while read -r rsz rpath; do n=$(basename "$rpath") lsz=$(stat -c%s "$L/$n" 2>/dev/null || echo 0) [ "$rsz" != "$lsz" ] && echo "$rpath" >> "$L/redo.txt" done < "$L/remote.txt" NEED=$(wc -l < "$L/redo.txt") echo "第${round}轮: 需拉/重拉 $NEED 片" [ "$NEED" = "0" ] && break xargs -P8 -I% $SCP bt-server:% "$L/" < "$L/redo.txt" done BAD=0 while read -r rsz rpath; do n=$(basename "$rpath"); lsz=$(stat -c%s "$L/$n" 2>/dev/null || echo 0) if [ "$rsz" != "$lsz" ]; then echo "❌ 仍不完整: $n 本地=$lsz 远端=$rsz"; BAD=1; fi done < "$L/remote.txt" [ "$BAD" = "1" ] && { echo "分片校验未通过,中止"; exit 1; } echo "✅ 分片校验通过: $TOTAL 片 / $(du -cb "$L"/$P-* | tail -1 | cut -f1) 字节" $SSH test106 "rm -rf /tmp/$N; mkdir -p /tmp/$N" S=$(date +%s) $SCP "$L"/$P-* test106:/tmp/$N/ E=$(date +%s) echo "上传106: $($SSH test106 "ls /tmp/$N | wc -l") 片 耗时$((E-S))s" if [ -n "$DEST" ]; then $SSH test106 "cd /tmp/$N && cat $P-* > /tmp/$N.tgz && tar xzf /tmp/$N.tgz -C $DEST && echo '解包完成 → $DEST'" fi