Using the rsync command to synchronize files

I was wondering whether there's a way to get the rsync command to actually synchronize files rather than just supporting a one-way mirror. For example, if I push files A, B and C on HOST1 to HOST2, then change file B on HOST2 before pushing the files again, the copy of file B on HOST1 will overwrite the changes I made to file B on HOST2. That is not the behavior I'm looking for. I need a method that will merge the changes between the two hosts. I've heard of Unison, but there's no binary for AIX, and I won't be compiling any sources.
 
babyb00merAsked:
Who is Participating?
 
TomuniqueConnect With a Mentor Commented:
As KeremE said.  if the -u flag will prevent newer files from being over-written.
Then run rsync on both systems, pointing to each other.

A will copy to B
B will copy to A


whomever is the most recent version, the other side won't overwrite because of the -u, but the local rsync will copy  it back over to the other system.
0
 
Kerem ERSOYPresidentCommented:
Hi,

rsync will not do a bi-directional replication. At most you can add -u switch which will prevent the newer files to be overwritten by rsync.

For unison I am afraid currently no binaries available that I am aware of but you might like to compile your own.

Cheers,
K.
0
 
Kerem ERSOYPresidentCommented:
All I know about the binary distribution is a very old AIX 4.3 binary. I am not sure if you can run it over your system though.

Here's the link for the old binary:

http://www.bullfreeware.com/download/aix43/unison-2.9.1.0.exe

Cheers,
K.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
TintinCommented:
I suppose NFS is out of the question?
0
 
liddlerCommented:
How about something like running a cronjob, say every minute on each server
on each server, detect a file newer than 1 minute old and rsync it to the other machine

find /myDir -mtime -1 -exec rsync -e ssh -aup /myDir/{} \; otherserver:/myDir  

I haven't checked the syntax, so you will need to test it.

Obviously this might have problems if the same file is updated on both servers within the same minute.... You could increase granularity by doing something like
touch /tmp/flag
sleep 20
find /myDir -newer /tmp/flag............
To check the last 20 seconds, you would probably run this not a a cron job, but in an infinite loop, as cron normally is no less that 1 minute

0
 
babyb00merAuthor Commented:
Hmmm. That looks like a viable solution. Given that scenario, Is it possible to use the --files-from option? I'd like to set up the command so that it's reading the source files/directories from a file on the disk. I thought something like this might work:

rsync -av --files-from=/directory/file --rsync-path=/usr/bin/rsync user@node:

0
 
Kerem ERSOYConnect With a Mentor PresidentCommented:
I was thinking as Tominque suggested but I was afraid that the second computer rsync operation would disrupt all the files in the first computer. But I've tried myself and observed none would be overwritten

So you can put a command like this in your cron in both systems:

Server1:
rsync -avuz  /some/path  user@server1:/some/path

Server2:
rsync -avuz  /some/path  user@server2:/some/path

Cheers,
K.
0
 
Kerem ERSOYPresidentCommented:
Of course it will also require you to have a passswordles ssh accounts set up at each end.
0
 
TomuniqueConnect With a Mentor Commented:
The --files should work.
I suspect that it would just be used instead of an `ls` of the directory.
It should still do timestamp checks to determine differences.  The fact that it got the file from a file  list, vs a directory list shouldn't matter.

That said, I've not done it before.
0
 
babyb00merAuthor Commented:
The comments by the experts were quite helpful. Incidentally, while I could run many of their examples from the command line of my Sun SPARC running an old version of Solaris 10, the rsync command with the -e option and reading the file list from standard input failed when invoked from within a shell script. Regardless, the solution worked on the target system, so I chalked it up to a quirk in the OS or the shell I was using on the Sun system.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.