无法在我的服务器和 Mac 之间进行 rsync

发布于 2024-07-17 21:04:39 字数 869 浏览 5 评论 0原文

我有一台服务器,用于存储 Mac A 和 Mac B 的数据。

我使用 rsync 来保持 Mac 之间的文件更新。

我运行以下代码失败,

#!/bin/zsh

#    to copy files from my server to my folder
rsync -Pav $Masi:~/private/ ~/Dropbox/Courses/math/

#    to  copy files from my folder to my server
rsync -Pav ~/Dropbox/Courses/math $Masi:~/private/

收到以下错误消息:

ssh: connect to host  port 22: Connection refused
rsync: connection unexpectedly closed (0 bytes received so far) [receiver]
rsync error: unexplained error (code 255) at io.c(600) [receiver=3.0.5]
ssh: connect to host  port 22: Connection refused
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(600) [sender=3.0.5]

我有 ssh 密钥,因此连接应该可以工作,因为我可以毫无问题地使用 scp。

如何在我的服务器和我的一台 Mac 之间使用 rsync?

I have a server where I store data from Mac A and Mac B.

I use rsync to keep the files updated between my Macs.

I run the following code unsuccessfully

#!/bin/zsh

#    to copy files from my server to my folder
rsync -Pav $Masi:~/private/ ~/Dropbox/Courses/math/

#    to  copy files from my folder to my server
rsync -Pav ~/Dropbox/Courses/math $Masi:~/private/

I get the following error message

ssh: connect to host  port 22: Connection refused
rsync: connection unexpectedly closed (0 bytes received so far) [receiver]
rsync error: unexplained error (code 255) at io.c(600) [receiver=3.0.5]
ssh: connect to host  port 22: Connection refused
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(600) [sender=3.0.5]

I have ssh keys in place so the connection should work, since I can use scp without problems.

How can you use rsync between my server and one of my Macs?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

鱼窥荷 2024-07-24 21:04:39

我曾经做过很多这样的事。 刚刚测试了一下,提几点建议。

  1. 拼出你的整个 user@host 模式
  2. 首先运行 ssh 连接而不使用 rsync,你可能需要首先批准你的指纹
  3. 你似乎没有传递一个标志来保护扩展属性,这可能会在 OS X 上产生损坏的文件。如果你这样做不需要资源分叉,你可以,但大多数时候你确实需要它们。

我的测试用例:

$ rsync -Pav ~/Desktop/ [email protected]:~/rsyc-test

在这种情况下,~/Desktop 中的所有文件都被复制到远程主机的我的主目录中。 由于目录“rsyc-test”不存在,因此它是为我创建的。 我的桌面上有一个 .app,它成功了,令人惊讶的是,它可以工作。 甚至一些 .webloc 文件也成功了并且看起来可以工作,尽管我不信任它。

我强烈建议添加 -E 标志

<前><代码> -E, --扩展属性
用于复制扩展属性、资源的 Apple 特定选项
分叉和 ACL。 至少需要 Mac OS X 10.4 或适当版本
修补了 rsync。

我运行了一个新的测试,将 Interarchy 书签移动到我的桌面,我知道如果没有资源分叉复制它们,这些书签就会被破坏。 在不使用 -E 的情况下与使用 -E 的情况下运行时,xfered 数据存在 152 字节的差异。 远程计算机上的第一个文件不起作用,第二个传输的文件起作用。

我不禁注意到,在您的示例中,您的路径之一是 ~/Dropbox,因此这可能并不重要,因为 DropBox 应用程序目前根本不支持资源分叉,尽管我听说将来有计划。

您也不会发送 --delete 标志,如果您的最终目标是数据的镜像,那么您就不会得到这一点,如果您的最终目标是不断增长的备份,保留源上的所有内容,则缺乏--delete 很好。

其他注意事项:
您可以排除那些愚蠢的 .DS_Store 文件
--exclude '.DS_Store'

您还可以将 rsync 设置为真正的镜像,这样您就不需要运行其他命令,有关详细信息,请参阅手册页。

我的最终工作命令是将笔记本电脑的桌面推送到远程计算机:

$ rsync -PEav --delete --exclude '.DS_Store' ~/Desktop/ [email protected]:~/rsycn-test

I used to do a lot of this. Just ran a test, a few suggestions.

  1. Spell out your entire user@host pattern
  2. Run the ssh connection sans the rsync first, you may need to first approve your fingerprint
  3. You do not seem to pass a flag to protect extended attributes, this can yield broken files on OS X. If you do not need resource forks, you are OK, but most of the time you do need them.

My test case:

$ rsync -Pav ~/Desktop/ [email protected]:~/rsyc-test

In that case, all the files within ~/Desktop were copied to the remote host, in my home dir. Since the directory 'rsyc-test' did not exist, it was made for me. I had a .app on my Desktop, it made it over, surprisingly, it works. Even some .webloc files made it and appear to work, though I do not trust it.

I would strongly suggest adding in the -E flag

  -E, --extended-attributes
         Apple specific option  to  copy  extended  attributes,  resource
         forks,  and  ACLs.   Requires at least Mac OS X 10.4 or suitably
         patched rsync.

I ran a new test, moved a Interarchy bookmark to my desktop, I know for a fact these break if they are copied sans resource forks. Running without the -E versus with the -E, there is a difference of 152 bytes in xfered data. The first file on the remote machine did not work, the second transfered file did work.

I can not help but notice in your example one of your paths is ~/Dropbox so this may all not matter, since DropBox, the app, does not at all support resource forks currently, though I hear there are plans to in the future.

You also are not sending in the --delete flag, if your end goal is a mirror of your data, you are not getting that, if your end goal is backups that continually grows, keeping everything that was ever on the source, the lack of --delete is good.

Other notes:
You can exclude those silly .DS_Store files
--exclude '.DS_Store'

You can also set rsync up in a way to be a true mirror, so you would not need to run your other command, see the man page for details.

My final working command to shove the Desktop of my laptop to a remote machine:

$ rsync -PEav --delete --exclude '.DS_Store' ~/Desktop/ [email protected]:~/rsycn-test
躲猫猫 2024-07-24 21:04:39

检查“$Masi”。 这是您要访问的主机名吗?

尝试使用以下命令进行调试:

rsync -e 'ssh -v' -Pav $Masi:~/private/ ~/Dropbox/Courses/math/

Check "$Masi". Is that the hostname you are trying to reach?

Try the following command to debug it:

rsync -e 'ssh -v' -Pav $Masi:~/private/ ~/Dropbox/Courses/math/
浸婚纱 2024-07-24 21:04:39

连接被拒绝通常发生在远程(例如防火墙)存在连接问题时。

在您的情况下,问题是 $Masi 变量为空。 如果它不是变量,请使用 Masi

根据这个错误:

ssh:连接到主机端口 22:连接被拒绝

注意上面的主机单词后面的双空格。

连接到主机 消息没有说明哪个主机,因此您正在尝试连接到空主机。 所以这听起来像是主机名中的拼写错误。

The Connection refused usually happens when there is a connection issue to the remote (e.g. firewall).

In your case the problem is that $Masi variable is empty. If it's not variable, use Masi.

As per this error:

ssh: connect to host port 22: Connection refused

Notice the double space above after the host word.

the connect to host message doesn't say to which host, so you're trying to connect to empty host. So it sound like a typo in the host name.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文