rsync具體同步參數的使用介紹

rsync具體參數的使用

4.1Rsync指定同步文件和目錄進行同步

測試演示:

1指定多個文件和目錄進行同步

參數:--files-from

--files-from="/tmp/list.txt"

[root@zabbix-server mh.com]# cat /tmp/list.txt

scripts

plus

e/action/

以上都是目錄

[root@zabbix-server mh.com]# /usr/bin/rsync -avrz--files-from="/tmp/list.txt" /home/wwwroot/mh.com/  [email protected]::mhttongbu3--password-file=/etc/passwd.txt

sending incremental file list

e/

e/action/

e/action/2.php

e/action/23.php

e/action/3.php

plus/

plus/4.php

plus/5.php

scripts/

scripts/.js

scripts/1.js

scripts/2.js

scripts/3.js

scripts/4.js

scripts/5.js

sent 753 bytes received 233 bytes  1972.00bytes/sec

total size is 59 speedup is 0.06

 

文件和目錄同時寫入文件列表進行同步

[root@zabbix-server mh.com]# cat/tmp/list.txt

scripts

plus

e/action/

21.html

230.html

c.html

提示:文件列表不支持*.html格式的文件名

[root@zabbix-server mh.com]# /usr/bin/rsync -avrz--files-from="/tmp/list.txt" /home/wwwroot/mh.com/  [email protected]::mhttongbu3--password-file=/etc/passwd.txt

 

sending incremental file list

21.html

230.html

c.html

e/

e/action/

e/action/2.php

e/action/23.php

e/action/3.php

plus/

plus/4.php

plus/5.php

scripts/

scripts/.js

scripts/1.js

scripts/2.js

scripts/3.js

scripts/4.js

scripts/5.js

 

sent 931 bytes received 290 bytes  814.00bytes/sec

total size is 65 speedup is 0.05

 

4.2rsync使用--include參數與--exclude參數來實現同步指定目錄,並且--exclude目錄放在後面。

演示:

參數:--include 結合參數exclude

只想同步plus 和scripts這兩個目錄,其他的不同步。

[root@zabbix-server mh.com]#/usr/bin/rsync -avrz --include "plus/" --include "scripts"--exclude "/*" /home/wwwroot/mh.com/ [email protected]::mhttongbu3 --password-file=/etc/passwd.txt

sending incremental file list

./

plus/

plus/4.php

plus/5.php

scripts/

scripts/.js

scripts/1.js

scripts/2.js

scripts/3.js

scripts/4.js

scripts/5.js

sent 533 bytes received 171 bytes  469.33bytes/sec

total size is 38 speedup is 0.05

解釋:

include plus/include scripts/include “”包含了你要同步的目錄exclude包含了其他不同步的目錄用“/*”指定。

--exclude /* 除了--include同步的目錄外,排除其他的目錄

/home/wwwroot/mh.com/ 指本地要同步的目錄,

[email protected]::mhttongbu3指遠程服務器上指定的目錄

把本地的目錄同步到遠程服務器指定的目錄下

mhttongbu3 爲模塊名稱 tongbu_user同步的用戶

 

4.3參數--exclude-from

--exclude-from指不同步那些文件和目錄

演示一:

/usr/bin/rsync -avrz--exclude-from="/tmp/list.txt1" /home/wwwroot/mh.com/  [email protected]::mhttongbu3--password-file=/etc/passwd.txt
sending incremental file list
./
21.html
230.html
30.html
c.html
lsd.html
q.html
test00001.html
test001
1/
13/
a34325/
adnc/
e/

 

[root@zabbix-server mh.com]# cat /tmp/list.txt1
plus
e/action
scripts

 


演示二:


[root@VM_82_178_centos 1]# cat /tmp/file.list 
txt01
txt02/1
jianwei01
test001

[root@VM_82_178_centos 1]# rsync -avzh  --password-file=/tmp/pass.txt --exclude-from=/tmp/file.list [email protected]::backup /data/www/jianwei.com
receiving incremental file list
txt02/
txt02/2/
sent 87 bytes  received 124 bytes  422.00 bytes/sec
total size is 42  speedup is 0.20




4.4參數--delete --exclude={a..f}.txt

客戶端:rsync -avz --delete --exclude={a..f}.txt /tmp/[email protected]::backup --password-file=/etc/rsync.password指定密碼文件,這樣界面就不提示數碼了。可以自動完成操作。同時--exclude={a..f}.txt是選擇性排除保留服務端的內容,防止客戶端數據把服務端數據全替換掉。


 4.5參數--exclude 介紹說明

排除rsync客戶端不需要同步的文件或者是目錄

排除不需要同步的文件名,排除不需要同步的目錄

[root@VM_82_178_centos txt01]# ll /data/www/jianwei.com/*
-rw-r--r-- 1 root root    7 Aug 22 16:42 /data/www/jianwei.com/jianwei01
-rw-r--r-- 1 root root    6 Aug 22 16:16 /data/www/jianwei.com/test001
/data/www/jianwei.com/txt01:
total 0
/data/www/jianwei.com/txt02:
total 8
-rw-r--r-- 1 root root  7 Aug 22 16:45 jianwei02
-rw-r--r-- 1 root root 23 Aug 22 16:48 jianwei03
[root@VM_82_178_centos txt01]# 

演示一:
[root@VM_82_178_centos txt01]# rsync -avzh  --password-file=/tmp/pass.txt --exclude "jianwei01" --exclude=txt01 --exclude "txt02/jianwei02" --exclude=txt02/jianwei03 [email protected]::backup /data/www/jianwei.com
receiving incremental file list

sent 92 bytes  received 88 bytes  120.00 bytes/sec
total size is 6  speedup is 0.03
[root@VM_82_178_centos txt01]#

演示二:同步txt01目錄,不同步jianwei01文件,不同步txt02/jianwei02文件,不同步txt02/jianwei03文件

[root@VM_82_178_centos txt01]# rsync -avzh  --password-file=/tmp/pass.txt --exclude=jianwei01  --exclude "txt02/jianwei02" --exclude=txt02/jianwei03 [email protected]::backup /data/www/jianwei.com
receiving incremental file list
txt01/
txt01/1.txt
txt01/2.txt
txt01/3.txt
sent 150 bytes  received 265 bytes  276.67 bytes/sec
total size is 6  speedup is 0.01
[root@VM_82_178_centos txt01]#


5.rsync參數介紹

http://blog.csdn.net/stevenprime/article/details/7601261

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章