Force rsync timeout on stalled connection

rsync

I have a problem with a defective round robin data mover node I'm rsync'ing data from. One of the nodes keeps dropping the data connection to the file system my data is coming from and needs to reconnect, which can take up to several minutes. During this time, the rsync on that particular file does not abort, it just hangs, for up to several minutes, until the download continues. Because this is time critical data, that is not a viable option, but instead should drop the connection asap when it stalls, and reconnect (which would then be load balanced to the next node anyway).

Can anyone think of a method to tell rsync to abort a transfer that's been stalled for more than e.g. 20 seconds?

The operator of the broken data mover nodes are slow to react to this problem, they're aware of it, but not doing anything at the moment, so I need to find a solution at my end.

I've tried using the –timeout option, but that doesn't seem to work when a data connection is stalled.

Best Answer

You can run rsync with --timeout=SECONDS to exit after stalled file transfers. More recent versions of rsync have --contimeout=SECONDS for connection timeouts.

# timeout after 20 seconds
rsync --timeout=20 source destination

# timeout after 3 seconds of no connectivity
rsync --contimeout=3 source destination

More helpful example: https://explainshell.com/explain?cmd=rsync+--timeout%3D60+-aP+--append-verify+--stats+user%40host%3A%2Ffolder+%2Fcygdrive%2Ff%2Fbackup