1

I have a source directory which I'm periodically syncing to a target using rsync:

rsync --bwlimit=1600 --recursive --times
      --omit-dir-times --copy-links --modify-window=30
      --inplace --delete-before --progress --stats --whole-file
      --itemize-changes --human-readable ./ /media/0123-4567/

The target media is just the right size for the sync: the target is a 1000 MB partition, source has 990 MB of files; syncing from source to an empty target works fine.

The problem is when I'm syncing to a target which contains an older version: some of the existing source files are smaller in the current version, and some new are added. The total size stays 990 MB; but rsync seems to choose a strategy "copy new files first, then update the existing," the first part won't work, because the space that's supposed to be freed with the update is not there yet.

                                       version 1     version 2
 files not changed:                     800 MB        800 MB
 new files in v2:                         0 MB         80 MB
 files changed between versions:        190 MB        110 MB 

 total                                  990 MB        990 MB

In other words, how can I make rsync update the target first (which will, in my case, free up space), and only then add new files?

So far, I have hacked around this by having two separate invocations, only differing in this parameter:

rsync --existing [...]
rsync --ignore-existing [...]

This will update the existing files first, and copy the new ones later; Is there a way to do this with one command?

2
  • Note that there is similar functionality for files which don't exist in the new version: --delete-before; I haven't found any *--update-before or somesuch in the manpage. May 11, 2014 at 11:48
  • Also, using a larger target partition is not possible (the target is not a common-off-the-shelf disk, I need to work with what I have). May 11, 2014 at 11:50

1 Answer 1

3

So far, I have hacked around this by having two separate invocations, only differing in this parameter:

rsync --existing [...]
rsync --ignore-existing [...]

Yes, that's the correct way.

This will update the existing files first, and copy the new ones later; Is there a way to do this with one command?

No need:

  • From speed perspective, you are only sacrificing some negligible overheads
  • From documentation perspective, this is much clearer in stating what you are doing than some implicit ways.
1
  • Good points - the stat overhead for --times should be negligible; if I were using --checksum, it might have an effect. May 11, 2014 at 14:39

You must log in to answer this question.

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