简体   繁体   English

通过 ssh 传输后 rsync 挂起

[英]rsync hangs after transfer over ssh

I wrote a bash script that backs up files from a webserver (HostGator) to a local file server running FreeBSD.我编写了一个 bash 脚本,用于将文件从网络服务器 (HostGator) 备份到运行 FreeBSD 的本地文件服务器。

I use rsync over ssh (from the file server) to connect to the remote server (I already have pre-shared rsa keys setup).我通过 ssh(来自文件服务器)使用 rsync 连接到远程服务器(我已经预先设置了共享的 rsa 密钥)。 When I run the following line to start the sync, the files all seem to come in just fine, but the command never returns and the script just hangs forever:当我运行以下行开始同步时,文件似乎都很好,但命令永远不会返回并且脚本永远挂起:

/usr/local/bin/rsync -az --chown=root:admin --chmod=ugo=rwX --exclude ".inode_lock" --rsh='ssh -p2222' admin@domain.com:/home/admin/ '/mnt/blah/blah/LocalBackup/' >> "./Logs/Backup Log.txt"

After waiting a few minutes, when I hit Ctrl+C to stop the command, I poops out the following error messages:等待几分钟后,当我按 Ctrl+C 停止该命令时,我弹出以下错误消息:

^CKilled by signal 2.
rsync error: unexplained error (code 255) at rsync.c(636) [generator=3.1.2]
rsync error: received SIGUSR1 (code 19) at main.c(1429) [receiver=3.1.2]

This still happens even if the both sides are already synced and it is just checking for changes.即使双方已经同步并且只是检查更改,这种情况仍然会发生。

I'm not sure what do to do troubleshoot the problem.我不确定如何解决问题。 I did try removing the -v switch for rsync as some users reported that caused hangs, but I saw no differences.我确实尝试删除 rsync 的 -v 开关,因为一些用户报告说这会导致挂起,但我没有看到任何区别。

EDIT编辑

One more additional note.再补充一点。 I ran the script again today to continue to troubleshoot.我今天再次运行脚本以继续进行故障排除。 If I leave the script running without disturbing it after it hangs, eventually I receive the following message:如果我让脚本在挂起后继续运行而不打扰它,最终我会收到以下消息:

rsync: connection unexpectedly closed (2984632408 bytes received so far) [receiv    er]
rsync error: error in rsync protocol data stream (code 12) at io.c(226) [receive    r=3.1.2]
rsync: connection unexpectedly closed (8689703 bytes received so far) [generator    ]
rsync error: unexplained error (code 255) at io.c(226) [generator=3.1.2]

and then returns back to the command prompt.然后返回到命令提示符。 I'm think this might be due to a timeout on the remote server's end but not sure.我认为这可能是由于远程服务器端超时但不确定。 But I'm still not sure why the hang is happening though.但我仍然不确定为什么会发生挂起。

UPDATE更新

I did an additional test and limited the rsync transfer to a specific test folder with some sample files and subfolders, rather than grabbing the entire home directory.我做了一个额外的测试,并将 rsync 传输限制到包含一些示例文件和子文件夹的特定测试文件夹,而不是抓取整个主目录。 When I did this, it was able to successfully complete the transfeer and exit appropriately.当我这样做时,它能够成功完成传输并适当退出。 So it appears that there must be somee file or folder somewhere in the home directory of the server that is causing the problem.因此,在导致问题的服务器主目录中的某处似乎必须有一些文件或文件夹。 Are there any specific cases where rsync wouldn't be able to transfer a file?是否存在 rsync 无法传输文件的特定情况? I have seen it throw errors while trying to sync files that are write-locked, with a "Permission Denied" error, but even these files didn't stop it from continuing on.我已经看到它在尝试同步被写锁定的文件时抛出错误,并出现“权限被拒绝”错误,但即使是这些文件也没有阻止它继续。 Any thoughts?有什么想法吗?

As an additional note, the remote server I'm connecting to is on a shared hosting account so I don't have root access.另外要注意的是,我要连接的远程服务器位于共享主机帐户上,因此我没有 root 访问权限。 I don't know if this could be causing some problems?我不知道这是否会导致一些问题?

UPDATE 2更新 2

So I studied the rsync command and added a couple more commandline parameters --progress and --stats (along with --verbose) so I could better understand where it is dying.因此,我研究了 rsync 命令并添加了更多命令行参数 --progress 和 --stats(以及 --verbose),以便我可以更好地了解它在哪里死亡。 What I noticed now is that when running the command, where it was hanging was on a verrry large file that was being downloaded from the server.我现在注意到的是,当运行命令时,它挂在一个从服务器下载的大文件上。 But now with the --progress being reported (I am having it output directly to the terminal for the moment rather than a file), it seems to be moving along just fine, with no hangups so far.但是现在随着 --progress 被报告(我现在将它直接输出到终端而不是文件),它似乎进展顺利,到目前为止没有挂断。

I am now beginning to suspect that maybe the ssh connection is timing out or something due to inactivity?我现在开始怀疑 ssh 连接是否超时或由于不活动而导致? Especially since in the original situation, nothing gets output from the function for a long time while the large file transfer is happening.特别是因为在原始情况下,在进行大文件传输时,函数长时间没有任何输出。 Is this a possible scenario?这是一种可能的情况吗? If so, what could I do to hold the connection open?如果是这样,我该怎么做才能保持连接打开? (I'm not sure it's a good idea to print the --progress updates directly to the log file). (我不确定将 --progress 更新直接打印到日志文件是个好主意)。

OK, I figured it out.好的,我想通了。 Apparently HostGator's Shared servers have an SSH timeout limit of 30-45 minutes set by default.显然,HostGator 的共享服务器默认设置了 30-45 分钟的 SSH 超时限制。 Since running rsync took longer than that limit, it was closing the connection on.由于运行 rsync 花费的时间超过该限制,因此它正在关闭连接。 I called and spoke to their tech support and they got it increased for my server.我打电话并与他们的技术支持人员交谈,他们为我的服务器增加了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM