【发布时间】:2014-07-26 08:23:02
【问题描述】:
我们需要尽快将15TB 的数据从一台服务器传输到另一台服务器。我们目前正在使用rsync,但是当我们的网络能够达到900+Mb/s(使用iperf 测试)时,我们只能获得大约150Mb/s 的速度。我已经对磁盘、网络等进行了测试,并认为只是 rsync 一次只传输一个文件导致速度变慢。
我找到了一个脚本,可以为目录树中的每个文件夹运行不同的 rsync(允许您限制 x 个数),但我无法让它工作,它仍然一次只运行一个 rsync。
我找到了script here(复制如下)。
我们的目录树是这样的:
/main
- /files
- /1
- 343
- 123.wav
- 76.wav
- 772
- 122.wav
- 55
- 555.wav
- 324.wav
- 1209.wav
- 43
- 999.wav
- 111.wav
- 222.wav
- /2
- 346
- 9993.wav
- 4242
- 827.wav
- /3
- 2545
- 76.wav
- 199.wav
- 183.wav
- 23
- 33.wav
- 876.wav
- 4256
- 998.wav
- 1665.wav
- 332.wav
- 112.wav
- 5584.wav
所以我希望为 /main/files 中的每个目录创建一个 rsync,一次最多可以创建 5 个。所以在这种情况下,将运行 3 个 rsync,分别用于 /main/files/1、/main/files/2 和 /main/files/3。
我这样尝试过,但它一次只为 /main/files/2 文件夹运行 1 个 rsync:
#!/bin/bash
# Define source, target, maxdepth and cd to source
source="/main/files"
target="/main/filesTest"
depth=1
cd "${source}"
# Set the maximum number of concurrent rsync threads
maxthreads=5
# How long to wait before checking the number of rsync threads again
sleeptime=5
# Find all folders in the source directory within the maxdepth level
find . -maxdepth ${depth} -type d | while read dir
do
# Make sure to ignore the parent folder
if [ `echo "${dir}" | awk -F'/' '{print NF}'` -gt ${depth} ]
then
# Strip leading dot slash
subfolder=$(echo "${dir}" | sed 's@^\./@@g')
if [ ! -d "${target}/${subfolder}" ]
then
# Create destination folder and set ownership and permissions to match source
mkdir -p "${target}/${subfolder}"
chown --reference="${source}/${subfolder}" "${target}/${subfolder}"
chmod --reference="${source}/${subfolder}" "${target}/${subfolder}"
fi
# Make sure the number of rsync threads running is below the threshold
while [ `ps -ef | grep -c [r]sync` -gt ${maxthreads} ]
do
echo "Sleeping ${sleeptime} seconds"
sleep ${sleeptime}
done
# Run rsync in background for the current subfolder and move one to the next one
nohup rsync -a "${source}/${subfolder}/" "${target}/${subfolder}/" </dev/null >/dev/null 2>&1 &
fi
done
# Find all files above the maxdepth level and rsync them as well
find . -maxdepth ${depth} -type f -print0 | rsync -a --files-from=- --from0 ./ "${target}/"
【问题讨论】:
标签: bash shell ubuntu-12.04 rsync simultaneous