rsync 預設安裝的
遠端 192.168.1.123
本地 192.168.1.124
rsync + ssh
在本地主機執行
rsync -az [email protected]:/root /bak #目錄
rsync -az [email protected]:/root/ /bak #目錄裡面的内容
或者
在遠端主機
rsync -az /root [email protected]:/bak
rsync -az /root/ [email protected]:/bak
rsync用戶端 + rsync服務端
服務端
建立同步賬号檔案(匿名則不需要)
echo "zongxuan:zongxuan" > /etc/rsyncd_users.db
權限必須嚴格,否則同步會失敗
chmod 600 /etc/rsyncd_users.db
建立 /etc/rsyncd.conf 共享設定
uid = nobody #指定該子產品以指定的 UID 傳輸檔案,同步一些敏感的就root
gid = nobody #指定該子產品以指定的 GID 傳輸檔案。
use chroot = yes
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
[zongxuan]
path = /tmp
comment = rsync test
read only = yes
dont compress = *.gz *.bz2 *.tgz *.zip #不壓縮
auth users = zongxuan
secrets file = /etc/rsyncd_users.db #指定賬号檔案的路徑
啟用 rsync --daemon 服務
追加到開機
echo “/usr/local/bin/rsync --daemon” >>/etc/rc.local
yum -y install xinetd
chkconfig rsync on
chkconfig xinetd on
service xinetd restart
用戶端
浏覽共享
rsync [email protected]::tools
同步
mkdir /root/mysrc
rsync -avz --delete [email protected]::zongxuan /bak/ #下行同步,删除mysrc中多餘檔案
用戶端隻要配置密碼檔案即可。
# cd /etc
vim rsyncd.secretes
echo "zongxuan" > /etc/rsyncd.secretes
chmod 600 /etc/rsyncd.secretes
/usr/bin/rsync --avz --password-file=/etc/rsyncd.secretes --progress [email protected]::zongxuan /bak/
rsync 實時同步(inotify監控及觸發)
tar zxf inotify-tools-3.13.tar.gz
cd inotify-tools-3.13
./configure
make && make install
inotifywait -mrq -e modify,move,create,delete,attrib /my | while read X Y Z ; /usr/bin/rsync --avz --password-file=/etc/rsyncd.secretes --progress
[email protected]::zongxuan /bak/ ; done