-1

I've been using rsync to backup my "main" hdd quite successfully with the following command

rsync -aivr --delete --progress /src/my-files/ /dest/my-files

But I carry my external drive on the go and I might modify files on it. The above command would wipe out those changes. I can't just swap src and dest either because I may have changes on both drive that I want to preserve.

The behavior I want is something like this...

# rsync walks the src drive
# if a file is present in src that is not present in dest, then copy the file to dest
# if a file is present both in src and in dest, then compare modification times
#     and overwrite using the later one.
# if a file is present on dest but is not on src, then copy the file from dest to src.

Could I use rsync to get the above behavior?

DeepDeadpool
  • 1,263

1 Answers1

3

rsync is a one-way operation. You can try to implement two-way replication with it but it is fragile and prone to error. However, you can prevent rsync from removing a newer file on the destination with the --update switch:

   -u, --update
          This forces rsync to skip any files which exist on the destination and have a modified time that is newer  than  the  source  file.   (If  an
          existing destination file has a modify time equal to the source file's, it will be updated if the sizes are different.)

          In  the  current implementation of --update, a difference of file format between the sender and receiver is always considered to be important
          enough for an update, no matter what date is on the objects.  In other words, if the source has a directory or a symlink where  the  destina-
          tion has a file, the transfer would occur regardless of the timestamps. 
DopeGhoti
  • 76,081