0

I have these directories SRC, DST, COMPARE:

  • /opt/SRC

    file1
    file2
    file3
    
  • /opt/DST

    file1
    file2
    
  • /opt/COMPARE

    empty

I wish:

$ ls /opt/COMPARE
file3

But when I run :

rsync -avz --compare-dest=/opt/COMPARE /opt/SRC/ /opt/DST

The /opt/COMPARE directory is still empty, why?

0

I believe that you are applying the --compare-dest incorrectly.

From man rsync

   --compare-dest=DIR
          This option instructs rsync to use DIR on the destination machine as an  additional
          hierarchy  to  compare  destination files against doing transfers (if the files are
          missing in the destination directory).  If a file is found in DIR that is identical
          to  the  sender’s  file, the file will NOT be transferred to the destination direc‐
          tory.  This is useful for creating a sparse backup of just files that have  changed
          from  an  earlier  backup.  This option is typically used to copy into an empty (or
          newly created) directory.

         Beginning in version 2.6.4, multiple --compare-dest directories  may  be  provided,
          which  will  cause  rsync  to  search  the list in the order specified for an exact
          match.  If a match is found that differs only in attributes, a local copy  is  made
          and  the attributes updated.  If a match is not found, a basis file from one of the
          DIRs will be selected to try to speed up the transfer.

         If DIR is a relative path, it is relative to the destination directory.   See  also
          --copy-dest and --link-dest.

         NOTE:  beginning with version 3.1.0, rsync will remove a file from a non-empty des‐
          tination hierarchy if an exact match is found in one of  the  compare-dest  hierar‐
          chies (making the end result more closely match a fresh copy).

If I am reading this correctly, --compare-dest used used to stop the sending certain files. This would allow you to create a new copy destination directory, containing only files that have changed since the last copy. Sort of an incremental copy, if you will.

0
  1. rsync will compare the files in /opt/SRC to the files in /opt/COMPARE. If file exists in /opt/SRC and doesn't exist in /opt/COMPARE, or different version of it exists in both, it will copy it to /opt/DST.
  2. rsync is not only inspecting content when deciding if files are "identical". For this to work correctly, you should sometimes use flags like "--no-times" (this oneworked for me in one occasion), or "--no-perms", "--no-owner", "--no-group, "--checksum", etc.
  3. it is a good idea to use "--dry-run" to test the behavior, without actually copy.

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.