32

I happen to know about rsyn, and I use rsync to sync between my mac and a linux server as follows.

rsync -r -t -v MAC LINUX
rsync -r -t -v LINUX MAC

I expected to run the first command to sync, but I needed the second command also when a change is made in LINUX.

Am I missing something? Does rsync have an option to sync between two directories?

6 Answers 6

26

You want bi-directional sync. Take a look at unison, which does this: http://www.cis.upenn.edu/~bcpierce/unison/

For example, on Debian/Ubuntu:

$ sudo apt-get install unison
$ unison MAC/ LINUX/

If you have trouble with permissions (example ext4 -> FAT):

$ unison -perms 0 vlc-2.2.0/ /media/sf_vlc/vlc
Contacting server...
Looking for changes
Reconciling changes

vlc-2.2.0      vlc                
new dir  ---->            /  [f] 

Proceed with propagating updates? [] y
Propagating updates
1
  • If you use rsync and the devices have the same filesystems, you can sync all permissions. unison does not support this use-case.
    – MountainX
    Dec 6, 2020 at 23:20
13

It has been claimed that rsync was not recommended for two-way sync by its developers, but a source for this statement is lacking.

The already recommended unison utility will be a better solution for you.

Also keep in mind that you probably have to deal with a lot of Mac specific HFS+ stuff when using rsync. So be sure to use a properly patched rsync3 on the Mac or expect problems with modification dates (when using the Mac OS X provided rsync 2.6.9.) If you don't know how to build a properly patched rsync 3 for the Mac, get mlbackup which includes just that. (Full disclosure: I am the author of mlbackup.) Get it from github and be sure to download the full package from the downloads. (The mlbackup repo does not include rsync 3 which you want in this case.) http://github.com/MacLemon/mlbackup

7
  • 6
    A link to the non-recommendation by rsync developers would be nice.
    – Wildcard
    Dec 14, 2016 at 20:34
  • @Wildcard not from the developers, but this is relevant.
    – user298742
    Jul 11, 2018 at 3:17
  • @Ploni that page makes very limited use of rsync's features. I would not take it as definitive in regard to bidirectional sync with rsync.
    – MountainX
    Dec 6, 2020 at 23:15
  • @MountainX you cannot use rsync for bidirectional synchronisation if you want to be able to propagate deletions either way Dec 6, 2020 at 23:51
  • @roaima Why not? I'm testing it and it seems to be working. What am I missing?
    – MountainX
    Dec 6, 2020 at 23:55
5

I coded this small tool for my own needs:

https://github.com/dooblem/bsync

It uses rsync and can handle file moves.

1
  • Thank you. I see you have committed a bug fix as recently as Mar 5, 2019. I will be giving your tool a try.
    – MountainX
    Dec 6, 2020 at 23:01
5

You should also take a look at csync, which is open source and offers native bi-directional syncing.

FYI - as far as I know - csync is developed by people from the Samba team. And knowing that the Samba team also developed rsync, I take this as a token of quality.

1
2

Another excellent tool for bidirectional sync.....freefilesync

2
  • 5
    on Stack Exchange, we prefer answers that are more than just links. it would be great if you could expand a little on what this is (what makes it different from unison?)
    – strugee
    Nov 15, 2013 at 21:15
  • This project is a bit pushy in trying to get the users to make donations. Also, although source code is available. upstream does not host it on GitHub, GitLab or similar.
    – MountainX
    Dec 6, 2020 at 23:08
2

Another system that provides for synchronization of directories in both directions is SyncThing (Github) - "a continuous file synchronization program. It synchronizes files between two or more computers in real time, safely protected from prying eyes". There's also apps for mobile devices.

You must log in to answer this question.

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