linux - rsync fails after server restart

04
2013-09
  • SpawnST

    Usually I use the command

    rsync -av --delete someroot/somedir user@remote_server_ip:/someroot/.
    

    on my development server to synchronize somedir to a remote server. It worked fine. But after the remote server was restarted this command does not work anymore. It displays the following error messages:

    rsync: connection unexpectedly closed (0 bytes received so far) [sender]
    rsync error: error in rsync protocol data stream (code 12) at io.c(463) [sender=2.6.8]
    

    But the SSH service still works correctly. I can use ssh user@server_ipaddress to log in to the server. How can I make the rsync work again?

    update: rsync also doesn't work locally. it gives error as follows:

    [root@videochatweb1 web]# ./sync_client.sh
    building file list ... rsync: link_stat "/opt/web/client/index.php"     failed: Permission denied (13)
    done
    
    sent 29 bytes  received 20 bytes  98.00 bytes/sec
    total size is 0  speedup is 0.00
    rsync error: some files could not be transferred (code 23) at main.c(892)    [sender=2.6.8]
    

    update 2

    I compiled the source code of rsync and reinstall it on the server.Now it works.Thanks for all the suggestions.

  • Answers
  • Doug Harris

    Since the error message says "error in rsync protocol", this indicates that rsync is using the rsync protocol for communication and not ssh. So your test that shows that ssh is working is immaterial, but can lead to a solution.

    I think that the remote server may have been running rsync as a daemon (rsync --daemon) prior to reboot. It wasn't restarted automatically after reboot.

    I see two solutions:

    1. Restart rsync --daemon on the remote server. Put it into something in /etc/init.d or similar so that it restarts after the next reboot.
    2. Use ssh protocol for rsync instead.

    To use ssh for rsync, set the environment variable:

    export RSYNC_RSH=ssh
    

    or add -e ssh to your rsync command.

  • jhcaiced

    Sometimes, those rsync error codes are due to different versions of rsync between the client and server, can you check the version number of both ?

    • What OS are you using both on the client and the server machine ?

  • Related Question

    linux - rsync start from begin after a power cut off
  • arsane

    It seems that rsync save a temporary file at local when I sync a big file on remote.

    Then the machine encounter a abrupt shut down for power off.

    After I start the machine again, it seems that rsync syn the big file from begin, but I found that there is one file already synced about 60%(1G), what's wrong of my rsync usage?

    command I used:

    rsync --partial -av -r --progress user@remote /local-dir
    

  • Related Answers
  • James Polley

    As Tim said, this sounds normal; rsync will know that it's got a file that seems to be a partial copy of the remote file, but it still has to check that the file it has is in fact the file you're copying from.

    As it's doing this check, it will show the number of bytes of the file it has "transferred", so it will look as though it's copying the file again - but if you look at the speed of the transfer, it should be much faster than would be possible across the network. Eventually rsync will get past the bytes it's already copied and find new bytes that need to be transferred across the network, and then you'll see the speed slow down.

    In short, I think you're being confused by rsync's output, as it doesn't differentiate between "bytes transferred across the network" and "bytes transferred simply by checking that the local copy matches the remote copy"

  • Tim Robinson

    This is normal. rsync should be going back through the files it's already transferred to check for updates.

    The -u flag causes rsync to look at file modification times; if you add this it should skip the files that haven't changed on the source.

  • ttsiodras

    Just rename the temp file (.somethingXYZ) to the correct filename (something) from the remote source.

    Then rsync will DEFINITELY only download the missing stuff.

    (If you watch the folder when running rsync, you will see a new .somethingABC file being generated, which will grow by tens of MB/second... because rsync will be reading from the "half-done" local file instead of downloading it again from the remote source over the network).