8

I am trying to setup bi-direction or two way sync with rsync. In my case I only need to delete the files when syncing from B to A. So, I was thinking of running rsync twice as follow :

rsync -rtuv ./A/ ./B/
rsync -rtuv --delete ./B/ ./A/

This problem with this solution is that when I run rsync (B->A) which would be right after running the rsync (A-B), Any new file that get created in between the sync will also get removed.

Is there a way I can specify a time stamp as condition that it only delete the file if it created before this date/time.

Updated:

I understand there is a unison solution but the problem with unison is required to install on both ends. I am syncing with a remote server and I can not install unison on the remote end.

3

You could try osync which is designed for exactly this task. I once set up a complex sequence of rsync commands to do the job, but I now use osync.

https://github.com/deajan/osync

It uses rsync internally, so it should be suitable for any situation where you could use rsync.

  • 1
    Thanks, Mark. I was just about to answer my own question. I found very similar script called bsync (github.com/dooblem/bsync) basically it uses diff to figure out whats need to be sync. Since I am not expecting any conflicts in sync, I also modify this script a little so it run silently when runs with a cron job. – Raza Jan 19 '16 at 17:25
4

rsync is the wrong tool for this task, for exactly the reasons that you have encountered. Instead, consider using unison:

unison A/ B/

The first time you run this it will identify files that are uniquely in A, and those that are uniquely in B. It will also flag those that are in both places and ask you to identify which is to be overwritten.

The next time you run this it will copy changes from A to B and also B to A, flagging any files that have been changed in both places for manual resolution.

mkdir A B
date > A/date
who > B/who
unison A/ B/
# Lots of output from unison, showing synchronisation

ls A
date    who
ls B
date    who

date > A/date
unison A/ B/
# Lots of output from unison, showing synchronisation

There are a number of useful flags available for unison which help automate the process by defining assumptions and thereby reducing the number of questions you're asked during the synchronisation.

  • 3
    I saw unison solution but the problem with that is I am required to install on both end. I am syncing with a remote and I can not install unison on the remote end. – Raza Jan 19 '16 at 16:14
  • 1
    It doesn't help the OP, but I was looking for unison. I see there are Debian packages and it supports ssh transport. – Ted Jan 2 '17 at 18:22
  • 1
    There are possibilities to use unison without installing it on the server, see the comments in this answer stackoverflow.com/a/2936711 which points to i3vi3v.wordpress.com/2013/01/09/… – Thomas Jan 7 at 17:00
0

What you really need is Rclone. Rclone is rsync for cloud storage (box,dropbox,nextcloud,ftp etc) and local storage.

  • 2
    How would they install and use rclone to solve their problem? – Jeff Schaller Feb 24 at 14:18
  • 1
    rclone doesn't have bidirectional sync yet. – sean Jun 27 at 19:12

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.