Unison+inotify-tools實現Ubuntu主機間的多機觸發式雙向同步
阿新 • • 發佈:2019-02-12
安裝OpenSSH
在各臺伺服器上安裝OpenSSH,使用如下命令:
sudo apt-get install openssh
該命令在你的機器上同時安裝了SSH Server和SSH Client。
安裝Unison
在各個需要同步的伺服器上執行以下命令安裝unison:
sudo apt-get install unison
安裝Inotify tools
在各個需要同步的伺服器上執行以下命令安裝inotify-tools:
apt-get install inotify-tools
UNISON=`ps -ef |grep -v grep|grep -c inotifywait`
if [ ${UNISON} -lt 1 ]
then
#ip2="192.168.1.7"
src2="/home/hedy/src/"
dst2="/home/hedy/target/"
/usr/bin/inotifywait -mrq -e create,delete,modify,move $src2 | while read line
do
#/usr/local/bin/unison -batch $src2 ssh://$ip2/$dst2
/usr/bin/unison -batch $src2 $dst2
echo -n "$line " >> /home/hedy/log/inotify/inotify$(date +%u).log
echo ` date +%F\ %T " " -f1-4` >> /home/hedy/log/inotify/inotify$(date +%u).log
done
fi