The Linux Page

rsync backup generating a connection unexpectedly closed, error in rsync protocol data stream

Description

I wrote a small shell script (bash) to make a backup of one of my hard drive to another. Really, a very very simple script. It has one rsync command per partition. So I have one variable to define all the options and one rsync call per partition:

   options="... --one-file-system ..."
   rsync $options / /backup/root

I specifically show the --one-file-system option. It is very important to backup the / folder otherwise everything would be copied... It is likely very important for all your partitions. There are other flags to use to keep data as a good duplicate (i.e. a duplicate you can boot from and use as a complete system.)

The script worked great for all the partitions but one...

Problem

For that one I'd get the following error:

  (Server) Protocol versions: remote=29, negotiated=29
  rsync: connection unexpectedly closed (232164 bytes received so far) [sender]
  rsync error: error in rsync protocol data stream (code 12) at io.c(454) [sender=2.6.9]

I looked into it and found all sorts of things on the Internet talking about such an error, but no solution... until I found one that was saying that this was due to a memory buffer overrun or something of the sort (a free() would attempt to delete a buffer at the wrong address.)

Research

This bug is said to be fixed in rsync version 3.0.0pre8 and up.

Now, since I still have 2.6.9 and prefer to keep the system as it is so upgrades work automatically, it was not a good option to look into getting 3.x, compile and use that version.

I knew of a problem that was generating a lot of problems: having a filesystem that changes too much and especially if one of the files is owned by rsync. I had some --exclude and thus thought that would not be the problem.

Yes. Well... That was not the problem! (I moved the log file to /tmp which I do not backup--I wonder why?!

Solution

My screwy --exclude orders would actually prevent the rsync server from creating some folders that were necessary to complete the command. It should have been a bit more verbose about the problem, I guess.

Once I fixed my --exclude, the backup finally worked every time.