參數
-n 測試傳輸狀態 是否成功 dry-run
-a 歸檔 相當於 ugtopD等
-v 顯示同步過程
-z 壓縮
-t time時間信息
-g gourpID 屬組ID
-o owner 屬主ID
-e 指定協議或通道 ssh -p 22
-p 保持原來的權限
-D devices設備文件
--delete 無差異進行同步
--exclude 排除 多個可以使用 --exclude={a,b,c,d}
--exclude-form 排除多個文件 可以使用 --exclude-from=file.txt
--progress 顯示備份過程
--config=file 指定rsyncd.conf的配置路徑
rsync講解
#Global Settings
uid = nobody
gid = nobody
use chroot = no(是否禁錮用戶家目錄)
max connections = 10(最大連接數)
strict modes = yes(是否完全檢查)
pid file = /var/run/rsyncd.pid 運行進程ID
log file = /var/log/rsyncd.log 運行日誌
lock file=/var/run/rsync.lock 鎖文件
#Directory to be synced
[data]
path = /data 路徑
ignore errors = yes(是否忽略錯誤)
read only = no(只讀)
write only = no(只寫)
hosts allow = white_list_ip/net 白名單
hosts deny = black_list_ip/net 黑名單
list = false 是否允許列出名單
auth users = username (允許的用戶)
secrets file = /etc/rsync.passwd 用戶密碼的存放位置
#Global Settings uid = nobody gid = nobody use chroot = no max connections = 10 strict modes = yes pid file = /var/run/rsyncd.pid log file = /var/log/rsyncd.log lock file=/var/run/rsync.lock #Directory to be synced [data] path = /data ignore errors = yes read only = no write only = no hosts allow = 172.16.0.0/24 hosts deny = 0.0.0.0/32 list = false auth users = user100 secrets file = /etc/rsync.passwd
rsync --daemon 模式
rsync -avz ./index.php [email protected]::data --password-file=/etc/rsync.passwd
rsync ssh通道模式
rsync -avz -e "ssh -p 22" ./index.php [email protected]:/data
host=172.16.30.100
src=/data
dst=data
user=user100
pwd=/etc/rsync.passwd
cmd=/usr/local/inotify-tools-3.14/bin
#
#cd /usr/local/inotify-tools-3.14/bin
${cmd}/inotifywait -mrq --format '%f' -e create,close_write,delete $src \
| while read line
do
cd $src
rsync -aruz -R --delete ./ ${user}@${host}::${dst} --password-file=/etc/rsync.passwd >/dev/null 2>&1
done
Inotify講解