Основная проблема с вашим скриптом заключается в том, что вы открываете отдельное соединение scp
для каждого файла, которое добавляет лот ненужных накладных расходов. Вместо этого вы можете попробовать что-нибудь вроде этого:
#!/usr/bin/env bash
readonly PRIMARY=/export/home/david/dist/primary
readonly SECONDARY=/export/home/david/dist/secondary
readonly FILERS_LOCATION=(machineB machineC)
readonly MEMORY_MAPPED_LOCATION=/data/pe_t1_snapshot
PRIMARY_PARTITION=(0 548 272 4 544 276 8 556 280 12 552 284 16 256 564 20 260 560 24 264 572)
SECONDARY_PARTITION=(1101 1374 1641 1371 1647 1098 1635 1365 1095 1638 1089 1362 1659 1359)
dir1=$(ssh -o "StrictHostKeyChecking no" david@${FILERS_LOCATION[0]} ls -dt1 "$MEMORY_MAPPED_LOCATION"/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] | head -n1)
dir2=$(ssh -o "StrictHostKeyChecking no" david@${FILERS_LOCATION[1]} ls -dt1 "$MEMORY_MAPPED_LOCATION"/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] | head -n1)
## Build your list of filenames before the loop.
for n in "${PRIMARY_PARTITION[@]}"
do
primary_files="$primary_files :$dir1"/t1_weekly_1680_"$n"_200003_5.data
done
## Repeat for $SECONDARY_PARTITION
for n in "${SECONDARY_PARTITION[@]}"
do
secondary_files="$secondary_files :$dir2"/t1_weekly_1680_"$n"_200003_5.data
done
if [ "$dir1" = "$dir2" ]
then
## I am using find largely because the *
## in rm -rf "$PRIMARY"/* screws up the syntax
## highlighting on the site and it is a good habit to
## get into anyway. Feel free to use rm -rf in your script.
find "$PRIMARY" -mindepth 1 -delete
find "$SECONDARY" -mindepth 1 -delete
## rsync can be run with this format:
## rsync user@dest:/target/path1 :/target/path2 :/target/pathN /dest/path
#
## which is why I added the : in the loop above. So, these commands will
## open only 2 conections per file list. First you will try to copy all $primary_partition
## files from machineA, then all $primary_partition files from machineB.
## rsync will complain about files not found (which is why I'm redirecting standard
## error to /dev/null) but will continue. You then repeat the process for machineC.
rsync -avz david@${FILERS_LOCATION[0]}"${primary_files}" $PRIMARY/ 2>/dev/null
rsync -avz david@${FILERS_LOCATION[1]}"${primary_files}" $PRIMARY/ 2>/dev/null
## Do the same for $secondary_partition files
rsync -avz david@${FILERS_LOCATION[0]}"${secondary_files}" $SECONDARY/ 2>/dev/null
rsync -avz david@${FILERS_LOCATION[1]}"${secondary_files}" $SECONDARY/ 2>/dev/null
fi
readonly TGT=/export/home/david/dist
readonly TGT1=${TGT}/primary
readonly TGT2=${TGT}/secondary
readonly MMAP_LOC=/data/pe_t1_snapshot
readonly PART1='t1_weekly_1680_[03579]_200003_5.data' # shell globbing does
readonly PART2='t1_weekly_1680_[12468]_200003_5.data' # the bulk of the work
readonly F_LOC=BC
readonly SSH="david@machine"
#hoping the = works - I don't know
SSH1='ssh -o "StrictHostKeyChecking=no" '"${SSH}${F_LOC%?}"
SSH2="${SSH1%?}${F_LOC#?}"
DIR="${MMAP_LOC}/"'[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
DIR1="$($SSH1 'cd ${d='"$DIR"'} && echo $d')" #shell glob
DIR2="$($SSH2 'cd ${d='"$DIR"'} && echo $d')" #shell glob
${DIR1:?FAIL} [ -n "${DIR1#"$DIR2"}" ] && exit 1 #tests if d1=d2 or dies
F1="$($SSH1 'printf "%s\n" '"${DIR1}/${PART1}")" #prefers primary
F1="${F1}$(echo ; $SSH1 'for f in '"${DIR2}/${PART1}"'\ #shell glob in
do { case "'"$F1"'" in "${f#'"$DIR2"'}") continue ;;\ # favor
*) printf "%s\n" "$f" ;;\ #of files found in primary
esac ; } ; done')" #with secondary as backup
F2="$($SSH2 'printf "%s\n" '"${DIR2}/${PART2}")" #secondary
rsync -avzt -e "${SSH1}:/" "${TGT1}"/. \ #if it works, based on your
--exclude=* $(printf --include=%s\\n $F1) #file sizes, should
rsync -avzt -e "${SSH2}:/" "${TGT2}"/. \ #dramatically decrease
--exclude=* $(printf --include=%s\\n $F2) #transfer times
Это работает?