開源 快速 多功能 全量及增量 本地遠端
已守護程序(socket)的方式傳輸資料
rsync 參數 源 目的
SYNOPSIS
Local: rsync [OPTION...] SRC... [DEST] source 源 dest目的
Access via remote shell:
Pull: rsync [OPTION...] [USER@]HOST:SRC... [DEST]
Push: rsync [OPTION...] SRC... [USER@]HOST:DEST
Access via rsync daemon:
Pull: rsync [OPTION...] [USER@]HOST::SRC... [DEST]
rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC... [DEST]
Push: rsync [OPTION...] SRC... [USER@]HOST::DEST
rsync [OPTION...] SRC... rsync://[USER@]HOST[:PORT]/DEST
直接本地同步 cp
# rsync -avz /etc/hosts /tmp/
删除檔案
# rsync -r --delete /null/ /hequan/ 讓/null/(空檔案) 和/hequan/下一樣
推送push
$ rsync -avz -e 'ssh' /etc/hosts [email protected]:~ -e指定通道
拉pull
$ rsync -avz -e 'ssh' [email protected]:~/hosts /home/hequan/
-v 詳細輸出
-z 壓縮傳輸
-a歸檔模式 = -rtopgDl 遞歸 保持檔案時間 屬主 權限 屬組資訊 裝置檔案資訊 軟連接配接
-e 使用信道協定
daeman 模式
# rsync --version
rsync version 3.0.6 protocol version 30
# yum install rsync -y
伺服器端
# vim /etc/rsyncd.conf 配置檔案
##rsyncd.conf start##
uid = rsync
gid = rsync
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[hequan]
path = /hequan/
ignore errors
read only = false
list = false
hosts allow = 192.168.10.0/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
#rsync_config_______________end
# rsync --daemon 已守護程序的方式啟動
# netstat -lntup | grep 873
tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 1768/rsync
# cat /var/log/rsyncd.log
2016/03/29 22:53:45 [1768] rsyncd version 3.0.6 starting, listening on port 873
建立使用者,授權 寫入使用者名密碼
# useradd rsync -s /sbin/nologin
# chown -R rsync.rsync /hequan/
# echo "rsync_backup:hequan" > /etc/rsync.password
# cat /etc/rsyncd.password
rsync_backup:hequan
使用者名:密碼
# chmod 600 /etc/rsync.password 降低權限
用戶端
# echo "hequan" > /etc/rsync.password 隻有密碼
# chmod 600 /etc/rsync.password
拉
#rsync -avz [email protected]::hequan /data/ hequan 是子產品
Password:
receiving incremental file list
./
test1
# rsync -avz [email protected]::hequan --password-file=/etc/rsync.password /data/
推
# rsync -avz /data/ [email protected]::hequan --password-file=/etc/rsync.password
vi /etc/rsyncd.conf 使用者 目錄 子產品 虛拟使用者 及密碼檔案
共享目錄 /hequan
建立rsync使用者 授權
建立密碼檔案, 複制配置檔案裡的路徑,然後添加密碼内容
内容虛拟使用者名:密碼
密碼檔案的權限
rsync --daemon
密碼檔案和服務端沒有關系
--password-file=/etc/rsync.password 密碼
/etc/rsync.password 600
同步
推 拉
本文轉自 295631788 51CTO部落格,原文連結:http://blog.51cto.com/hequan/1763780,如需轉載請自行聯系原作者