5

I want to synchronize a directory on the server A to a server B.

On the server A I created a file rsyncd.conf with the content:

uid             = rsync
gid             = rsync
use chroot      = no
pid file        = /var/run/rsyncd.pid

[share]
  comment = share
  path = /etc/dirtosync
  read only = false
  list = yes
  hosts allow = *
  auth users = rsync
  secrets file = /etc/rsyncd.secrets

And I created on the server A the file /etc/rsyncd.secrets with the content:

rsync:rsync

I also created on the server A the pid file, and the user rsync with the password rsync.

On the server A, on the file: /etc/default/rsync I put the value RSYNC_ENABLE to true and I started the rsync daemon with the command:

/etc/initd/rsync start

On the server A and the server B the owner and the group of the directory is rsync.

I launched on the machine B the command:

rsync -avzr rsync@<serverA>:/etc/dirtosync/* /etc/dirtosync/

I also tried on the server A the command

rsync -avzr /etc/dirtosync/* rsync@<serverB>:/etc/dirtosync/

With this two commands the result is the same: the files are synchronized just one time when I launch the command but after if I modify the files in the server A they aren't synchronize to the server B

Do I have to do something else to keep the file synchronized?

1

3 Answers 3

5

You misunderstand how rsync works. rsync does not automatically replicate changes - it is not like dropbox or similar software. rsync only synchronises files once each time it is run. If you want to synchronise more often, then put the rsync command in a cron script (eg. look in /etc/cron.daily). If you want something that automatically synchronises changes, like dropbox does, then look at a different project, such as Sparkle Share or ownCloud.

1

You may also use lsyncd: https://github.com/axkibe/lsyncd. I'm using so far and it's great for this.

0

The rsync syntax you've posted works assuming you've omitted the machine's host name/IP, but does not use the rsync share you've set up. To use the share, you would need to change your syntax as follows to use the share:

rsync -av rsync@MACHINE-A::share/ /etc/dirtosync/

However, that will still not set up a continual sync between those folders. What you seem to be after is a bi-directional sync for those folders, which is something that you can either set up in the cron or start using Unison file synchronization software.

Unison is not well maintained any more, and I have not used it myself, but I have heard great things about it. It keeps track of changes to files made in a directory that you've set up for synchronization, and periodically copies those files over using rsync or another (configurable) method.

If you're going to go the rsync-in-the-cron route, you will want to use the -u option which tells rsync to only copy over the newer files. You will run into issues with deleted files re-appearing with this approach, however.

You must log in to answer this question.

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