linux - Does a successful exit of rsync -acvvv s d guarantee identical directory trees?

07
2014-07
  • user259774

    I have two volumes, one xfs, and another ntfs - ntfs was empty, and xfs had 10 subitems.

    I needed to sync them.
    I initially copied a few of the subitems by dragging them over in a gui fm. Several of the direct descendants which i had dragged finished, apparently. One I stopped before it was done, and the rest I cancelled while it still appeared to be gathering information about the files.

    Then I ran rsync -acvvv xmp/ nmp/, where xmp and nmp are the volumes' respective mountpoints, which exited with a 0 status.
    find xmp -printf x | wc -c and find nmp -printf x | wc -c both return 372926.

    My question is: Am I guaranteed that the two drives' contents are identical?

  • Answers
  • mxlian

    TLNR: Given the fact that you have the same amount of files & dirs in both (source & dest) after a successful rsync, yes they are identical.

    An exit status of 0 will in this case mean that all the content of xmp/ is entirely in nmp/. But no the other way arround. It's an unidirectional process.

    To be strictly identical using rsync you also need to delete all possible content of nmp/ which is not present in xmp/ (called extraneous files in rsync manual) using the --delete parameter.


  • Related Question

    linux - rsync: delete only extraneous files with a timestamp earlier than the newest in the source directory
  • Jeff

    I am trying to keep two peer directories in sync using rsync. The problem I have is that new files can be added or deleted in either directory before a sync occurs.

    If a deletion occurs in one, then the --delete option would delete that file in the other location as long as it was chosen as the target first. Otherwise, if the directory with the stale file still in it was chosen as the source initially, then the file would be copied across to the directory we had previously deleted it from.

    If a file is created in one and that directory is not chosen as the source, then the file will be classed as extraneous by the --delete option and be removed, despite being a valid addition.

    Is there a way of making more intelligent deletions or excludes based on timestamps? If not, then I only see rsync as a master-slave tool, and not able to cope with a peer-peer relationship.


  • Related Answers
  • 8088

    You could hack a bash scipt together based on timestamps using CURL -I which gives you header info for the files.

    1. Check the timestamp:

      curl -I http://somesite.com/somefolders/somefile.script | grep Date:
      Date: Fri, 11 Feb 2011 06:24:40 GMT
      
    2. Convert time to timestamp:

      date --utc --date "Fri, 11 Feb 2011 06:24:40 GMT" +%s
      
      1297405480
      
    3. Use the timestamp to compare files:

      if [[ time1 == time2 ]]; then curl (upload file)
      

    I found this for Dropbox: http://davehope.co.uk/Blog/backup-your-linux-vps-to-dropbox/