linux下实现文件双向同步 unsion,unison做数据双向同步
介紹:
由于使用rsync+inotify做單向同步很出色,但是雙向同步卻很不理想,所以使用unison來做數(shù)據(jù)的雙向同步。Unison是一款跨windows/linux/MAC OS平臺的文件同步工具,不僅支持本地對本地同步,也支持通過SSH、RSH和Socket等網(wǎng)絡(luò)協(xié)議進(jìn)行同步。更棒的是,Unison支持雙向同步操作,你既可以從A同步到B,也可以從B同步到A,這些都不需要額外的設(shè)定。
環(huán)境:
系統(tǒng):centos 5.4
ocaml 3.09.3
unison 2.40.63
A主機(jī)10.10.11.85? B主機(jī)10.10.11.92
只需要在其中一臺主機(jī)安裝unison server端即可,這里以A主機(jī)為例
1.ocaml下載
wget http://caml.inria.fr/pub/distrib/ocaml-3.09/ocaml-3.09.3.tar.gz
2.unison下載最新穩(wěn)定版
wget http://www.seas.upenn.edu/~bcpierce/unison//download/releases/stable/unison-2.40.63.tar.gz
3.Ocaml安裝腳本如下:
tar -zxf ocaml-3.09.3.tar.gz
cd ocaml-3.09.3
./configure
make world opt
make install
cd ..
4.unison安裝腳本如下:
tar -zxf unison-2.40.63.tar.gz
cd unison-2.40.63
make UISTYLE=text
make install
cp unison /usr/local/bin
scp unison? 10.10.11.92:/usr/local/bin/
5.配置雙機(jī)ssh信任
A主機(jī):
ssh-keygen -t rsa
cd .ssh/
scp id_rsa.pub 10.10.11.92:/root/
B主機(jī)--10.10.11.92:
cat id_rsa.pub >>~/.ssh/authorized_keys
B主機(jī):
ssh-keygen -t rsa
cd .ssh/
scp id_rsa.pub 10.10.11.85:/root/
A主機(jī)--10.10.11.85:
cat id_rsa.pub >>~/.ssh/authorized_keys
6.通過配置文件來使用unison
使用root安裝unison后,配置文件默認(rèn)生成在/root/.unison/default.prf,可以手動寫一個(gè)配置文件,運(yùn)行unison時(shí)只需指定此配置文件即可。
下面以同步兩個(gè)不同主機(jī)的/mnt目錄為例的配置信息:
只在A主機(jī)中配置:
# more /root/.unison/unison_test.prf
root = /mnt
root = ssh://root@10.10.11.92//mnt
#force =/mnt
path = mnt
ignore = Path tmp
#prefer = ssh://root@10.10.11.92//mnt
batch = true
maxthreads = 180
#repeat = 1
#retry = 3
owner = true
group = true
perms = -1
fastcheck=false
rsync =false
#debug=verbose
sshargs = -C
xferbycopying = true
confirmbigdel = false
log = true
logfile = /root/.unison/unison_test.log
7.在A主機(jī)上做計(jì)劃任務(wù),進(jìn)行每兩分鐘自動同步
*/2 * * * * /usr/local/bin unison unison_test.prf? >/dev/null 2>&1 &
注各參數(shù)詳解:
——root表示需要同步的目錄
——force表示使用unison單項(xiàng)同步功能,注釋掉以便啟用雙向同步.
——ignore = Path表示同步/mnt目錄時(shí)不同步tmp。
——batch = true,表示全自動模式,接受缺省動作
——fastcheck? true,表示同步時(shí)使用文件的創(chuàng)建時(shí)間來比較兩地文件,如果這個(gè)選項(xiàng)為false,unison則將比較兩地文件的內(nèi)容.建議設(shè)置為true
——log = true
——logfile則指定了同時(shí)將輸出寫入log文件。
總結(jié)
以上是生活随笔為你收集整理的linux下实现文件双向同步 unsion,unison做数据双向同步的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: java代码家庭系谱图,高中生物--遗传
- 下一篇: ShowWindow函数
