我们需要转移15TB
尽可能快地将数据从一台服务器传输到另一台服务器。我们目前正在使用rsync
但我们只能得到大约的速度150Mb/s
,当我们的网络能够900+Mb/s
(测试与iperf
)。我已经对磁盘、网络等进行了测试,发现 rsync 一次只传输一个文件,从而导致速度变慢。
我找到了一个脚本来为目录树中的每个文件夹运行不同的 rsync(允许您限制为 x 个数字),但我无法让它工作,它仍然一次只运行一个 rsync。
我找到了script
here http://www.krazyworks.com/making-rsync-faster/(复制如下)。
我们的目录树是这样的:
/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
and /main/files/3
.
我尝试这样使用它,但它一次只运行 1 个 rsync/main/files/2
folder:
#!/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}/"