Answer the question
In order to leave comments, you need to log in
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/>
delete-after – Удалять файлы на слейве (#2), которые не были найдены на мастере (#1), после окончания синхронизации.<br/>
Так же можно использовать delete-before, delete-during, delete-excluded и delete.<br/>
Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question