S
S
sisaenkov2010-11-23 09:29:19
FreeBSD
sisaenkov, 2010-11-23 09:29:19

Two-way data synchronization on two servers?

There are:
2 FreeBSD servers (#1 and #2) running rsync, located in different apartments. Each server has one 500 GB hard drive that stores work and personal information.
Task:
Make a smart synchronization that would be able to:
1. When adding / deleting / changing information on server #1, it should be added / deleted / changed on server #2.
2. Similarly to item 1 in reverse order.
How I did:
On server #2, I added the following commands to the cron:

/usr/local/bin/rsync -avz -e 'ssh -p 22' --partial /hdd/docs/ [email protected]:/hdd/docs/ # с сервера #1 на сервер #2<br/>
/usr/local/bin/rsync -avz -e 'ssh -p 22' --partial [email protected]:/hdd/docs/ /hdd/docs/ # и наоборот<br/>

The problem arose when I started adding keys
delete-after – Удалять файлы на слейве (#2), которые не были найдены на мастере (#1), после окончания синхронизации.<br/>
Так же можно использовать delete-before, delete-during, delete-excluded и delete.<br/>

It turned out that the files on #1 just deleted/modified by the first command in the cron were re-created when #2 was synchronized with #1 by the second command, and vice versa.
Is there a solution?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
intnzy, 2010-12-21
@intnzy

csync2

I
ivlis, 2010-11-23
@ivlis

I do like this:

ESCDIR=$(echo "$DIR" |sed -e "s,\([]\(\).^\*\$\/&[]\),\\\\\1,g")

scp -p $DIR/.lastsync $HOST:$DIR

ssh $HOST find  $DIR/$SUBDIR  -newer $DIR/.lastsync | sed -e "s/$ESCDIR\///" | \
rsync  --exclude-from=- --delete -av $DIR/$SUBDIR $HOST:$DIR

rsync  --delete -av $HOST:$DIR/$SUBDIR $DIR 
rsync  --delete -av  $DIR/$SUBDIR $HOST:$DIR

DATE=`date`
echo "$DATE Syncing finished"
echo "====================================================="
echo "  "

touch $DIR/.lastsync

Assumes that files are not changed during the sync and the sync will not be interrupted. The latter is easy to fix, but the former cannot be done without a local db.

S
sisaenkov, 2010-11-23
@sisaenkov

So the problem is not that something changes during synchronization, but that one of the options will somehow roll over to the second, even if half of the files have already been deleted.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question