2

I know how rsync works. My doubt is how does rsync patches the parts which are different between source and destination file.

After calculating the block which is different, it sends that part to destination. Now how does the destination insert this in mid of file? Does it move all the subsequent bytes also because we can't insert (appending) byte in the mid of the file.

Suppose source : ABCDEFGH

destination : ABCEFGH

suppose rsync detects that D is missing it send that to destination. Than how destination insert D in to the file. Whether it insert after C and move EFGH or it does something else efficient. Because in any programing language we can not insert bytes in the mid of a file without replacing.

  • Why can't we? Open the file for write (appending), move pointer with lseek(), write. Or mmap() the file and simply modify the block you need. – Rmano Nov 22 '13 at 1:50
  • 1
    @Rmano please see my edits. – Trying Nov 22 '13 at 2:02
1

I only know about C implemenations of rsync, they work with the limitations most underlying filesystems. That means only if the file is exactly the same size data 'in the middle' can be updated.

However this is irrelevant. For security reasons rsync makes a copy of changed data and moves that in copy in place only if it is complete. rsync does not normaly try and update an existing file, which runs the risk of corruption if the process is interrupted.

You should look at the --delay-updates in the man page to understand the update process. That option allows you to delay the renaming until all files that need to change in one run are complete, and then rename.

  • Can you please help me understanding what you are saying by an example. Like i have give in the question. Thanks. – Trying Nov 23 '13 at 23:55
  • Your assumption is wrong, and so is your example. A new file is written, then the old one replaced. No inserting, shrinking, expanding is done. – Zelda Nov 26 '13 at 10:52
  • Are you saying that after getting diff part from src file the des file is newly created by adding the diff part where ever it should be? i.e. suppose src file contains: i am a good boy and des file contains: i good boy. so when ever rsync pass on the info about the missing things, here it is am a than the des1 (newly created file) file will be newly created by the content i am a good boy than delete des and des1 will be renamed to by des. Am i correct? – Trying Nov 26 '13 at 11:00
  • Yes a new file is created, when that process is complete (it might go wrong if data has to come over the Net etc), then src is deleted and dst renamed to src. – Zelda Nov 26 '13 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.