4

What is a best way to keep in sync two local folders ? I know I can use rsync -Ra but I need to keep in sync all the time. Is it possible to make rsync sit in background and constantly sync local folders.

Tom
  • 43
  • 3

1 Answers1

0

If you need to sync directories, and not just have a mirror copy of a directory, I recommend Unison, which we use in our environment. It can keep two local directories synchronized OR a local and a remote directory synchronized.

You can run it as a cron job to check and propagate any changes, or you can fire Unison "on-demand" using incrond which allows you to run Unison only if a file change was detected. I have not used the latter method, so I can't comment on it. We have Unison run every minute via cron to check for changes in the two directories, and it works well for us. It has a built-in lock mechanism so that it won't run another Unison process if one is currently running.

It utilizes rsync behind the scenes, and is very flexible in terms of specifying file exclusions. Priorities are also flexible, for example, if myfile.csv was altered in both directory A and B, so how should Unison handle this? You can use newest, oldest, prefer directory A, prefer directory B, etc...

Banjer
  • 3,974
  • 12
  • 41
  • 47