使用rsync同步通过网桥的两台计算机 [英] sync two computers going through a bridge with rsync

查看:52
本文介绍了使用rsync同步通过网桥的两台计算机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想同步两台计算机(A和C).不幸的是,我无法通过ssh从计算机A连接到计算机C(没人知道为什么).这就是为什么我必须使用C可以识别的另一台计算机(B)的原因.

I want to sync two computers (A and C). Unfortunately I cannot connect from the computer A to the computer C via ssh (no one knows why). This is why I have to use a another computer (B), which is recognized by C.

要同步A和C,我建立了两个脚本:第一个脚本"sync_A_2_B.sh"(位于A中)和"sync_B_2_C.sh"(位于B中).每个都包含rsync指令.

To sync A and C I build-up two scripts: the first one "sync_A_2_B.sh" (located in A), and "sync_B_2_C.sh" (located in B). Each of those contain rsync instructions.

从A到B:

rsync -av ~/BACK_UP/ username1@blablabla1:/home/BACK_UP/

从B到C:

rsync -av ~/BACK_UP/ username2@blablabla2:/home/BACK_UP/

这很完美,但是有点费时间.这引出了我的问题.是否可以在A中的一个脚本(" sync_A_2_C.sh)中执行这些操作,以便程序认为B是桥梁?我已经绑定了以下内容,但是它不起作用:

This works perfect, but it is a bit time consuming. This leads to my question. Would it be possible to perform these actions in one script located in A (""sync_A_2_C.sh) so that the program considers that B is a bridge? I have tied the following, but it does not work:

rsync -av ~/BACK_UP/ username1@blablabla1:/home/BACK_UP/
rsync -av username1@blablabla1:/home/BACK_UP/ username2@blablabla2:/home/BACK_UP/

尽管如此,它不能正常工作,因为源和目标不能同时在remmote桌面中.有可能轻松执行我想要的吗?我应该使用其他工具吗?

Nevertheless, it does not work, as source and target cannot be in a remmote desktop at the same time. Is there any possibility to easily perform what I want? Should I use another tool?

推荐答案

您可以使用 ProxyCommand 选项通过 ssh 来转发通过 B 的流量.这样做意味着文件根本不必存在于机器 B 上.例如(从机器A到C):

You could use the ProxyCommand option to ssh to forward the traffic through B. Doing this means that the files don't ever have to live on machine B at all. For example (going from machine A to C):

rsync -av -e 'ssh -o "ProxyCommand ssh -W %h:%p username1@B"' ~/BACK_UP/ username2@C:/home/BACK_UP/

或者您可以将ProxyCommand放入〜/.ssh/config文件中.像这样:

Or you can put the ProxyCommand in your ~/.ssh/config file. Something like:

Host C
   Hostname C
   User username2
   ProxyCommand ssh -W %h:%p username1@B

使用此方法,您应该可以从A到C透明地执行ssh

With this you should be able to do ssh transparently from A to C

这篇关于使用rsync同步通过网桥的两台计算机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆