linux – 如何并行化scp命令?

linux – 如何并行化scp命令?
我需要将文件从machineB和machineC scp到machineA.我从machineA运行我的下面的 shell脚本.我已正确设置了ssh密钥.

如果文件不在machineB中,那么它应该在machineC中.我需要将所有PARTITION1和PARTITION2文件移动到machineA各自的文件夹中,如下面的shell脚本所示 –

#!/bin/bashreadonly PRIMARY=/export/home/david/dist/primaryreadonly SECONDARY=/export/home/david/dist/secondaryreadonly FILERS_LOCATION=(machineB machineC)readonly MAPPED_LOCATION=/bat/data/snapshotPARTITION1=(0 3 5 7 9)PARTITION2=(1 2 4 6 8)dir1=$(ssh -o "StrictHostKeyChecking no" david@${FILERS_LOCATION[0]} ls -dt1 "$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 "$MAPPED_LOCATION"/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] | head -n1)length1=$(ssh -o "StrictHostKeyChecking no" david@${FILERS_LOCATION[0]} "ls '$dir1' | wc -l")length2=$(ssh -o "StrictHostKeyChecking no" david@${FILERS_LOCATION[1]} "ls '$dir2' | wc -l")if [ "$dir1" = "$dir2" ] && [ "$length1" -gt 0 ] && [ "$length2" -gt 0 ]then    rm -r $PRIMARY/*    rm -r $SECONDARY/*    for el in "${PARTITION1[@]}"    do        scp david@${FILERS_LOCATION[0]}:$dir1/t1_weekly_1680_"$el"_200003_5.data $PRIMARY/. || scp david@${FILERS_LOCATION[1]}:$dir2/t1_weekly_1680_"$el"_200003_5.data $PRIMARY/.    done    for sl in "${PARTITION2[@]}"    do            scp david@${FILERS_LOCATION[0]}:$dir1/t1_weekly_1680_"$sl"_200003_5.data $SECONDARY/. || scp david@${FILERS_LOCATION[1]}:$dir2/t1_weekly_1680_"$sl"_200003_5.data $SECONDARY/.    donefi

目前,我在PARTITION1和PARTITION2中有5个文件,但一般来说它将有大约420个文件,这意味着它将逐个移动文件,我认为这可能很慢.有没有办法加快这个过程?

我正在运行Ubuntu 12.04

并行化SCP会适得其反,除非双方都使用SSD. SCP最慢的部分是网络枯萎,在这种情况下,并行化根本不会有任何帮助,或者任何一方的磁盘,你会因并行化而变得更糟:寻找时间会杀了你.

你说machineA在SSD上,所以每台机器的并行化就足够了.最简单的方法是将第一个forloop包装在子shell中并将其背景化.

( for el in "${PARTITION1[@]}"do    scp david@${FILERS_LOCATION[0]}:$dir1/t1_weekly_1680_"$el"_200003_5.data $PRIMARY/. || scp david@${FILERS_LOCATION[1]}:$dir2/t1_weekly_1680_"$el"_200003_5.data $PRIMARY/.done ) &

推荐阅读