Is rsync really bidirectional or more unidirectional

file-transferrsync

So I understand that rsync works by using a checksum algorithm that updates files according to file size and date. But isn't this synchronization dependent on how source and destination are called? Doesn't the order of source to destination change the behavior of what gets synced?

Let me get to where I am going..

Obviously this input1

rsync -e ssh -varz ~/local/directory/ user@remote.login:~/remoteFolder/

is not the same as input2

rsync -e ssh -varz user@remote.login:~/remoteFolder/ ~/local/directory/

But I thought that either way you called rsync, the whole point of it was so that any file that is newer is updated between the local and remote destinations.

However, it seems that it's dependent on whether your new file is located under the source rather than the destination location. If I updated file1 on my local machine (same, but older file1 on server), saved it, and then used code2 to sync between locations, I noticed that the new version of file1 on my local machine does not upload to the server. It actually overwrote the updated file with the older version. If I use input2 it does upload modified to server.

Is there a way to run rsync in which it literally synchronizes new and modified files no matter whether source or destination locations are called first according to newer/modified file location?

Best Answer

No, rsync only ever syncs files in one direction. Think of it as a smart and more capable version of cp (or mv if you use the --remove-source-files option): smart in the sense that it tries to skip data which already exists at the destination, and capable in the sense that it can do a few things cp doesn't, such as removing files at the destination which have been deleted at the source. But at its core, it really just does the same thing, copying from a source to a destination.

As Patrick mentioned in a comment, unison will do what you're looking for, updating in both directions. It's not a standard tool, though - many UNIX-like systems will have rsync installed, but usually not unison. But on a Linux distribution you can probably find it in your package manager.

Related Question