在多个主机上并行rsync
我需要从15个不同的主机上获取一组文件。这些文件其实就是一些文本文件。
我已经设置好了ssh密钥之类的东西,现在可以用scp、ssh、rsync等命令无密码登录了。
现在我在寻找一种合适的方法来快速获取这些文件,并且能够跟踪进度(也就是说,我不想让它在后台运行,然后希望它能在某个时候完成,再开始处理这些文件)。
目前我对编程语言没有特别的偏好。无论是用shell、perl、python、ruby等都可以。
我只是想向这里的专家请教一下。
2 个回答
2
使用 fabric!特别是,你可能会对 并行执行 这一页感兴趣。
示例:
from fabric.api import env, run
env.user = 'implicit_user'
env.hosts = ['host1', 'explicit_user@host2', 'host3']
def print_user():
with hide('running'):
run('echo "%(user)s"' % env)
输出:
$ fab print_user
[host1] out: implicit_user
[explicit_user@host2] out: explicit_user
[host3] out: implicit_user
Done.
Disconnecting from host1... done.
Disconnecting from host2... done.
Disconnecting from host3... done.
1
试试 Perl 的 Net::OpenSSH::Parallel 模块:
use Net::OpenSSH::Parallel;
my $pssh = Net::OpenSSH::Parallel->new;
$pssh->add_host($_) for @hosts;
$pssh->push('*', scp_get => '/remote/file/path', '/local/file/path-%HOST%');
$pssh->run;
# do whatever you want with the local files.