My intention is to keep two remote directories (say dir1 & dir2) synced. So that whenever there is a change in the content of the dir1 (can be addition or deletion of new file or directory or modifying the content of a file in the directory) then the change should be propagated to dir2 and vice versa.
The naive way I can think of doing this is to run rsync periodically via cron in both the machines. But there are fallacies in this approach:-
- It might happen that the previous rsysnc is not complete and the cron executed rsync once more while the previous rysnc is still going on.
- A new file is added in dir1 and before rsync ran on dir2 rsync on dir1 ran then newly added file might be deleted from dir1 since it is not present in dir2
- Also this is not real time.
Can some suggest some better way of doing this? I am looking for open-source which will be easier to set-up and get started.