无法在我的服务器和 Mac 之间进行 rsync
我有一台服务器,用于存储 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我曾经做过很多这样的事。 刚刚测试了一下,提几点建议。
我的测试用例:
在这种情况下,~/Desktop 中的所有文件都被复制到远程主机的我的主目录中。 由于目录“rsyc-test”不存在,因此它是为我创建的。 我的桌面上有一个 .app,它成功了,令人惊讶的是,它可以工作。 甚至一些 .webloc 文件也成功了并且看起来可以工作,尽管我不信任它。
我强烈建议添加 -E 标志
我运行了一个新的测试,将 Interarchy 书签移动到我的桌面,我知道如果没有资源分叉复制它们,这些书签就会被破坏。 在不使用 -E 的情况下与使用 -E 的情况下运行时,xfered 数据存在 152 字节的差异。 远程计算机上的第一个文件不起作用,第二个传输的文件起作用。
我不禁注意到,在您的示例中,您的路径之一是 ~/Dropbox,因此这可能并不重要,因为 DropBox 应用程序目前根本不支持资源分叉,尽管我听说将来有计划。
您也不会发送 --delete 标志,如果您的最终目标是数据的镜像,那么您就不会得到这一点,如果您的最终目标是不断增长的备份,保留源上的所有内容,则缺乏--delete 很好。
其他注意事项:
您可以排除那些愚蠢的 .DS_Store 文件
--exclude '.DS_Store'
您还可以将 rsync 设置为真正的镜像,这样您就不需要运行其他命令,有关详细信息,请参阅手册页。
我的最终工作命令是将笔记本电脑的桌面推送到远程计算机:
I used to do a lot of this. Just ran a test, a few suggestions.
My test case:
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
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:
检查“$Masi”。 这是您要访问的主机名吗?
尝试使用以下命令进行调试:
Check "$Masi". Is that the hostname you are trying to reach?
Try the following command to debug it:
连接被拒绝通常发生在远程(例如防火墙)存在连接问题时。
在您的情况下,问题是
$Masi
变量为空。 如果它不是变量,请使用Masi
。根据这个错误:
注意上面的
主机
单词后面的双空格。连接到主机 消息没有说明哪个主机,因此您正在尝试连接到空主机。 所以这听起来像是主机名中的拼写错误。
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, useMasi
.As per this error:
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.