移动 2TB(1000 万个文件 + 目录),我的瓶颈是什么?

Tim*_*Tim 21 centos rsync ext3 ext4 mv

背景

跑出空位/home/data需要,并转移/home/data/repo/home/data2

/home/data/repo包含 1M 个目录,每个目录包含 11 个目录和 10 个文件。总共 2TB。

/home/data在启用 dir_index 的 ext3 上。 /home/data2在 ext4 上。运行 CentOS 6.4。

我认为这些方法很慢,因为repo/它下面有 100 万个目录。


尝试 1:mv速度快但被打断

如果这已经完成,我可以做到:

/home/data> mv repo ../data2
Run Code Online (Sandbox Code Playgroud)

但是在传输了1.5TB之后就中断了。它以大约 1GB/分钟的速度写入。

尝试 2:rsync在构建文件列表 8 小时后爬行

/home/data> rsync --ignore-existing -rv repo ../data2
Run Code Online (Sandbox Code Playgroud)

构建“增量文件列表”需要几个小时,然后以 100MB/分钟的速度传输。

我取消它以尝试更快的方法。

尝试 3a:mv抱怨

在子目录上测试它:

/home/data/repo> mv -f foobar ../../data2/repo/
mv: inter-device move failed: '(foobar)' to '../../data2/repo/foobar'; unable to remove target: Is a directory
Run Code Online (Sandbox Code Playgroud)

我不确定这是什么错误,但也许cp可以让我摆脱困境..

尝试 3b:cp8 小时后无处可去

/home/data> cp -nr repo ../data2
Run Code Online (Sandbox Code Playgroud)

它读取磁盘 8 小时,我决定取消它并返回到 rsync。

尝试 4:rsync在构建文件列表 8 小时后爬行

/home/data> rsync --ignore-existing --remove-source-files -rv repo ../data2
Run Code Online (Sandbox Code Playgroud)

我曾经--remove-source-files认为如果我现在开始清理可能会使其更快。

构建文件列表至少需要 6 个小时,然后以 100-200MB/分钟的速度传输。

但是服务器一夜之间负担过重,我的连接关闭了。

尝试 5:仅剩 300GB 可移动 为什么这如此痛苦

/home/data> rsync --ignore-existing --remove-source-files -rvW repo ../data2
Run Code Online (Sandbox Code Playgroud)

又打断了。在-W几乎似乎让“发送增量文件列表”更快,这对我的理解不应该是有意义的。无论如何,传输速度非常慢,我放弃了这一点。

尝试 6: tar

/home/data> nohup tar cf - . |(cd ../data2; tar xvfk -)
Run Code Online (Sandbox Code Playgroud)

基本上是尝试重新复制所有内容但忽略现有文件。它必须通过 1.7TB 的现有文件,但至少它的读取速度为 1.2GB/分钟。

到目前为止,这是唯一可以立即获得满足感的命令。

更新:以某种方式再次中断,即使使用 nohup ..

尝试 7: harakiri

还在争论这个

尝试 8:脚本化的“合并” mv

目标目录有大约 12 万个空目录,所以我跑了

/home/data2/repo> find . -type d -empty -exec rmdir {} \;
Run Code Online (Sandbox Code Playgroud)

红宝石脚本:

SRC  = "/home/data/repo"
DEST = "/home/data2/repo"

`ls #{SRC}  --color=never > lst1.tmp`
`ls #{DEST} --color=never > lst2.tmp`
`diff lst1.tmp lst2.tmp | grep '<' > /home/data/missing.tmp`

t = `cat /home/data/missing.tmp | wc -l`.to_i
puts "Todo: #{t}"

# Manually `mv` each missing directory
File.open('missing.tmp').each do |line|
  dir = line.strip.gsub('< ', '')
  puts `mv #{SRC}/#{dir} #{DEST}/`
end
Run Code Online (Sandbox Code Playgroud)

完毕。

Яро*_*лин 6

听说过将大任务拆分成小任务吗?

/home/data/repo 包含 1M 个目录,每个目录包含 11 个目录和 10 个文件。总共 2TB。

rsync -a /source/1/ /destination/1/
rsync -a /source/2/ /destination/2/
rsync -a /source/3/ /destination/3/
rsync -a /source/4/ /destination/4/
rsync -a /source/5/ /destination/5/
rsync -a /source/6/ /destination/6/
rsync -a /source/7/ /destination/7/
rsync -a /source/8/ /destination/8/
rsync -a /source/9/ /destination/9/
rsync -a /source/10/ /destination/10/
rsync -a /source/11/ /destination/11/

(...)
Run Code Online (Sandbox Code Playgroud)

咖啡休息时间。