環境規劃:服務端為 CentOS 6.3(10.1.4.44),客戶端為 Windows Server 2003 R2(10.1.4.42)。目標是讓 cwRsync 客戶端每天凌晨 02:30 自動把服務端 /data/share 的資料同步到本機 D:\data。所需檔案為 rsync-3.0.9.tar.gz 與 cwRsync_4.0.5_Installer.zip。
[root@server ~]# tar xvf rsync-3.0.9.tar.gz [root@server ~]# cd rsync-3.0.9 [root@server rsync-3.0.9]# ./configure --prefix=/usr [root@server rsync-3.0.9]# make [root@server rsync-3.0.9]# make install
建立設定檔目錄與三個檔案,並把密碼檔權限收緊:
[root@server etc]# mkdir rsyncd [root@server rsyncd]# touch rsyncd.conf [root@server rsyncd]# touch rsyncd.secrets [root@server rsyncd]# chmod 600 rsyncd.secrets [root@server rsyncd]# touch rsyncd.motd
rsyncd.conf 內容如下,注意 log file 這裡保持註解狀態以免干擾:
pid file = /var/run/rsyncd.pid port = 873 address = 10.1.4.44 uid = root gid = root use chroot = yes read only = yes hosts allow = 10.1.4.0/255.255.255.0 hosts deny = * max connections = 5 motd file = /etc/rsyncd/rsyncd.motd #log file = /var/log/rsync.log log format = %t %a %m %f %b syslog facility = local3 timeout = 300 [samba_data] path = /data/share list = no ignore errors auth users = root secrets file = /etc/rsyncd/rsyncd.secrets
密碼檔每行一組帳號與密碼:
root:111111 user:111111
兩個安全提醒:密碼檔屬主必須是 root、權限必須 600,否則備份必然失敗;另外不要在這裡填寫系統帳號的真正密碼,這與 Samba 的認證邏輯相同。
motd 檔只是登入時的歡迎訊息,非必填:
++++++++++++++++++++++++++++++++++++++++++++++ Welcome to use the mike.org.cn rsync services! 2002------2012 ++++++++++++++++++++++++++++++++++++++++++++++
[root@server ~]# /usr/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf [root@server ~]# netstat -anp |grep :873 tcp 0 0 10.1.4.44:873 0.0.0.0:* LISTEN 5696/rsync [root@server ~]# iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 873 -j ACCEPT [root@server ~]# iptables -L
驗證服務端有沒有把資料源推出來:
[root@server ~]# rsync --list-only root@10.1.4.44::samba_data
能列出 caiwu、jishu、public、yanfa 等目錄,就代表 list 設定與密碼都正常。
下載 cwRsync_4.0.5_Installer.zip,解壓後執行 installer,一路 Next、I Agree,預設安裝到 C:\Program Files\cwRsync,完成後關閉。
先測試與服務端是否通:
開始 - 執行 - cmd cd C:\Program Files\cwRsync\bin telnet 10.1.4.44 873
能進入 telnet 畫面即代表 873 埠暢通。
先在 D 槽建立 data 資料夾,然後執行:
C:\Program Files\cwRsync\bin>rsync --port=873 -vzrtopg --progress --delete root@10.1.4.44::samba_data /cygdrive/d/data
輸入密碼 111111 後開始同步。參數意義:/cygdrive/d/data 代表 D:\data;samba_data 是 rsyncd.conf 中的模股利名稱;-vzrtopg --progress 顯示詳細歷程;--delete 會刪掉本機多餘的檔案,確保兩邊完全一致。完成後可實際比對 D:\data 與服務端 /data/share 的內容。
在 C:\Program Files\cwRsync\bin 建立密碼檔 passwd.txt,內容只有一行 111111。再建立 samba.bat:
@echo off echo. echo 開始同步數據,請稍等... echo. cd C:\Program Files\cwRsync\bin rsync --port=873 -vzrtopg --progress --delete root@10.1.4.44::samba_data /cygdrive/d/data < passwd.txt echo. echo 數據同步完成 echo.
接著開啟 開始 - 設定 - 控制台 - 工作排程,加入新工作,瀏覽選取 samba.bat,觸發方式選「每天」,起始時間設 02:30,輸入系統管理員密碼後完成。從此跨平台的每日自動備份就上軌道了。