Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was reading several guides how combine btrfs snapshots with rsync to make an efficient backup solution with history. However it all depends on if rsync --inplace modifies only those portions of files that actually changed, or if it overwrites the whole file sequentially. If it writes the whole file then it seems that btrfs will always create a new copy of the file, which would make the idea much less efficient.

share|improve this question
    
How would it even know if it can avoid writing to the entire file? Doesn't it need to read the entire file first, to figure out what has changed? – Mehrdad Apr 1 '13 at 3:16
    
@Mehrdad yes, it does, but reading the whole isn't a problem. If rsync reads the whole file and then seeks to and updates only those parts that are needed, btrfs will copy only these updated blocks. But if rsync reads and writes the whole file, then it'll be a problem. – Petr Pudlák Apr 1 '13 at 14:36
1  
@Mehrdad rsync does not only know that it may avoid writing the entire file, it manages to do so without copying it completely over the net. Clever little program. – hirschhornsalz May 2 '13 at 11:24

If you pass rsync two local paths, it will default to using "--whole-file", and not delta-transfer. So, what you're looking for is "--no-whole-file". You also get delta-transfer if you requested '-c'.

Here's how you can verify:

$ mkdir a b
$ dd if=/dev/zero of=a/1 bs=1k count=64
$ dd if=/dev/zero of=a/2 bs=1k count=64
$ dd if=/dev/zero of=a/3 bs=1k count=64
$ rsync -av a/ b/
sending incremental file list
./
1
2
3

sent 196831 bytes  received 72 bytes  393806.00 bytes/sec
total size is 196608  speedup is 1.00

Then touch a file and re-sync

$ touch a/1
$ rsync -av --inplace a/ b/
sending incremental file list
1

sent 65662 bytes  received 31 bytes  131386.00 bytes/sec
total size is 196608  speedup is 2.99

You can verify it re-used the inode with "ls -li", but notice it sent a whole 64K bytes. Try again with --no-whole-file

$ touch a/1
$ rsync -av --inplace --no-whole-file a/ b/
sending incremental file list
1

sent 494 bytes  received 595 bytes  2178.00 bytes/sec
total size is 196608  speedup is 180.54

Now you've only sent 494 bytes. You could use strace to further verify if any of the file was written, but this shows it at least used delta-transfer.

share|improve this answer

--inplace overwrites only regions that have changed. Always use it when writing to Btrfs.

share|improve this answer
    
And do you have an evidence that shows it doesn't overwrite other parts of files? – Petr Pudlák Oct 25 '13 at 13:00
    
Does the same apply to ZFS? – ewwhite Jul 4 '14 at 6:39
    
@ewwhite: Since ZFS is COW (copy-on-write) like BTRFS, then yes. – Geremia Mar 2 '15 at 20:45

Here the definite answer I guess, citing the correct part of the manual:

   --inplace

          [...]

          This option is useful for transferring large files
          with  block-based  changes  or  appended data, and
          also on systems that are disk bound,  not  network
          bound.   It  can  also  help  keep a copy-on-write
                                               *************
          filesystem snapshot from diverging the entire con‐
          *******************
          tents of a file that only has minor changes.
share|improve this answer

Read all about it here: http://hssl.cs.jhu.edu/index.php?option=com_content&view=article&id=73:iprsync&catid=42:past&Itemid=58

Thanks to HOPKINS STORAGE SYSTEMS LAB for doing the hard theory on this!

share|improve this answer

rsync's delta transfer algorithm deals with whether the entire file is transmitted or just the parts that differ. This is the default behavior when rsyncing a file between two machines to save on bandwidth. This can be overriden with the --whole-file (or -W) to force rsync to transmit the entire file.

--inplace deals with whether rsync, during the transfer, will create a temporary file or not. The default behavior is to create a temporary file. This gives a measure of safety in that if the transfer is interrupted, the existing file in the destination machine remains intact/untouched. --inplace overrides this behavior and tells rsync to update the existing file directly. With this, you run the risk of having an inconsistent file in the destination machine if the transfer is interrupted.

share|improve this answer

From the man page:

This  option  changes  how  rsync transfers a file when its data
needs to be updated: instead of the default method of creating a
new  copy  of  the file and moving it into place when it is com-
plete, rsync instead writes the updated  data  directly  to  the
destination file.

This leads me to believe that it writes over the file in its entirety-- I imagine it would be near impossible for rsync to work any other way.

share|improve this answer
    
After determining what parts need update, it could just seek to those parts and update them, instead of writing the entire file. – Petr Pudlák Apr 1 '13 at 14:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .