我们需要尽可能快地将数据从一台服务器转移到另一台服务器。我们目前使用的是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
所以我想发生什么事是创建一个rsync的每个/主/文件的目录中,最多的,比方说,每次5个。所以在这种情况下,会运行3个rsyncs,对于/main/files/1
,/main/files/2
和/main/files/3
。
我与它试图这样,但它只是运行1个rsync的在时间/main/files/2
文件夹:
#!/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 '[email protected]^\./@@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}/"
刚刚试过这个,并不能得到这个工作。 'ls -1/main/files/* | xargs -i -n5 rsync -av {}/main/filesTest/{}'给了我很多rsync的文件或目录错误。我将如何打印出rsync命令而不是运行它,以便我可以看到发生了什么问题? – BT643
你可以将它从'rsync'改为'echo rsync' –
啊,对不起,'xargs'不对,应该是'parallel'。我已经更新了答案。 –