18

I was using a script to perform rsync in sudo crontab. The script does a 2-way rsync (from serverA to serverB and reverse). After I reboot both the server machines, the rsync is not working in sudo crontab. I also setup a new cronjob and it fails, The error is:

rsync error: unexplained error (code 255) at io.c(600) [sender=3.0.6]
rsync: connection unexpectedly closed (0 bytes received so far) [receiver]

However, when run from terminal, the rync script works as expected without issues. please help.

Rahul
  • 67
  • 1
  • 12
kabeer
  • 181
  • 1
  • 1
  • 3

5 Answers5

6

One of the reason of rsync connection being unexpectedly closed is the timeout issue, especially when it takes a while to calculate file checksums in order to check the differences on the remote host.

To avoid this problem, you need to add these settings into your ~/.ssh/config or /etc/ssh/ssh_config:

Host *
  ServerAliveInterval 30
  ServerAliveCountMax 6

and optionally similar on the remote server (in /etc/ssh/sshd_config), e.g.

ClientAliveInterval 30
ClientAliveCountMax 6

See: What the options ServerAliveInterval and ClientAliveInterval mean?

kenorb
  • 5,943
  • 1
  • 44
  • 53
  • Does `ServerAliveInterval`/`ServerAliveCountMax` need to be under a `Host` directive or can it also be defined globally on root level of the ssh config file? – mae Jun 04 '21 at 08:41
  • That's what the `Host *` (the asterisk meaning "all") is for. – Sixtyfive Aug 31 '21 at 21:12
4

A little hard to answer given the almost total lack of relevant information but as a general rule, if a command works from the prompt but not from a cron job it's because you need to specify the full path to the command(s). Cron jobs do not have a normal user environment, which especially means they don't have the same PATH as regular users do.

John Gardeniers
  • 27,262
  • 12
  • 53
  • 108
  • I used to have a similar problem with rsync 2.6.8, evidently a bug that terminated croned tranmissions randomly, but I don't remember if it had that error code. It was under CentOS 5.5 at that time. Later with newer CentOS versions rsync came into 3.x and the issue is gone for good. – David Ramirez Nov 14 '13 at 16:54
3

This appears to happen when the connection is refused:

ssh: connect to host port 2222: Connection refused

followed by rsync error:

rsync: connection unexpectedly closed (0 bytes received so far) [receiver] rsync error: unexplained error (code 255) at /SourceCache/rsync/rsync-45/rsync/io.c(453) [receiver=2.6.9]


Possible reasons:

  • In my scenario, I had a firewall issue. Punched a hole.
  • wrong password (unlikely to address your issue, but will cause the same error)
0

I have similar issues too, while I was sending roughly 50GB of data through the local network with the command

rsync -avhPW --progress . user@192.168.1.233:/path/to/target

The pipe broke a few times, but for the first few times I could just relaunch the command. However, after ~20 hours, the command stopped working with unexplained error. rsync didn't even compute the list of files of consideration. It is not the problem of timeout either - the target machine never received a request. I ended up rebooting the source machine. That made rsync work again.

Student
  • 101
  • 1
0

Please look at you fail2ban list.

use the command: "fail2ban-client set YOURJAILNAMEHERE unbanip IPADDRESSHERE" to unban it and try again.

womble
  • 95,029
  • 29
  • 173
  • 228