使用rsync通过多级SSH复制文件

时间:2022-04-10 16:44:36

I need to transfer around 4.2 GB of files from my local computer to a server B. However to ssh into server B, I need to ssh into server A.

我需要将大约4.2 GB的文件从本地计算机传输到服务器B.但是要ssh到服务器B,我需要ssh到服务器A.

Currently I'm copying files from my local computer to server A and then from server A to server B.

目前我正在将文件从本地计算机复制到服务器A,然后从服务器A复制到服务器B.

So the flow goes like this:

所以流程如下:

rsync -avz --del ~/Desktop/abc/ <my-user-name>@<server-A>:~/abc

rsync -avz --del~ / Desktop / abc / @ :〜/ abc

rsync -avz --del ~/Desktop/abc/ <my-user-name>@<server-B>:~/abc

rsync -avz --del~ / Desktop / abc / @ :〜/ abc

This is slow and copies 4.2 gb of data two times instead of one!

这很慢并且复制了4.2 gb的数据而不是一次!

Can I transfer files with rsync from my local computer to directly server B ?

我可以将带有rsync的文件从本地计算机传输到服务器B吗?

2 个解决方案

#1


7  

You can always use ssh with proxy command, which allows you to transfer files transparently. Using this config (~/.ssh/config):

您始终可以使用ssh with proxy命令,它允许您透明地传输文件。使用此配置(〜/ .ssh / config):

Host <server-A>
    User <user-A>

Host <server-B>
    User <user-B>
    ProxyCommand ssh <server-A> -W %h:%p

You can call your rsync:

你可以调用你的rsync:

rsync -avz --del ~/Desktop/abc/ <server-B>:~/abc

The data will be only "routed" over the middle host.

数据将仅在中间主机上“路由”。

#2


0  

What you want is to use port-forwarding to forward the ssh/rsync port (generally port 22) from server B to alternate ports on server A so when you call rsync -e "ssh -p altport" serverA:/sourcedir /destdir, you are actually invoking rsync from serverB.

你想要的是使用端口转发将服务器B的ssh / rsync端口(通常是端口22)转发到服务器A上的备用端口,所以当你调用rsync -e“ssh -p altport”serverA:/ sourcedir / destdir时,你实际上是从serverB调用rsync。

There are many good howtos available on StackExchange and other sites. For example:

StackExchange和其他网站上有很多好的方法。例如:

will get you started. Using port-forwarding, you are essentially using serverA as a pass-through host so you will only have to transfer your 4.2G once.

会让你开始。使用端口转发,您实际上使用serverA作为传递主机,因此您只需转移4.2G一次。

#1


7  

You can always use ssh with proxy command, which allows you to transfer files transparently. Using this config (~/.ssh/config):

您始终可以使用ssh with proxy命令,它允许您透明地传输文件。使用此配置(〜/ .ssh / config):

Host <server-A>
    User <user-A>

Host <server-B>
    User <user-B>
    ProxyCommand ssh <server-A> -W %h:%p

You can call your rsync:

你可以调用你的rsync:

rsync -avz --del ~/Desktop/abc/ <server-B>:~/abc

The data will be only "routed" over the middle host.

数据将仅在中间主机上“路由”。

#2


0  

What you want is to use port-forwarding to forward the ssh/rsync port (generally port 22) from server B to alternate ports on server A so when you call rsync -e "ssh -p altport" serverA:/sourcedir /destdir, you are actually invoking rsync from serverB.

你想要的是使用端口转发将服务器B的ssh / rsync端口(通常是端口22)转发到服务器A上的备用端口,所以当你调用rsync -e“ssh -p altport”serverA:/ sourcedir / destdir时,你实际上是从serverB调用rsync。

There are many good howtos available on StackExchange and other sites. For example:

StackExchange和其他网站上有很多好的方法。例如:

will get you started. Using port-forwarding, you are essentially using serverA as a pass-through host so you will only have to transfer your 4.2G once.

会让你开始。使用端口转发,您实际上使用serverA作为传递主机,因此您只需转移4.2G一次。