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/  tongbu_user@10.0.0.11::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/  tongbu_user@10.0.0.11::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/ tongbu_user@10.0.0.11::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/ 指本地要同步的目录,

 tongbu_user@10.0.0.11::mhttongbu3指远程服务器上指定的目录

把本地的目录同步到远程服务器指定的目录下

mhttongbu3 为模块名称 tongbu_user同步的用户

 

4.3参数--exclude-from

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

演示一:

/usr/bin/rsync -avrz--exclude-from="/tmp/list.txt1" /home/wwwroot/mh.com/  tongbu_user@10.0.0.11::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/
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.

 

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

 


演示二:


[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 rsync_backup@192.168.1.233::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
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.




4.4参数--delete --exclude={a..f}.txt

客户端:rsync -avz --delete --exclude={a..f}.txt /tmp/rsync_backup@172.16.1.41::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]# 

演示一:
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
[root@VM_82_178_centos txt01]# rsync -avzh  --password-file=/tmp/pass.txt --exclude "jianwei01" --exclude=txt01 --exclude "txt02/jianwei02" --exclude=txt02/jianwei03 rsync_backup@192.168.1.233::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]#
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.

演示二:同步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 rsync_backup@192.168.1.233::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]#
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.


5.rsync参数介绍

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

posted @ 2017-09-04 11:34  勤奋的蓝猫  阅读(12)  评论(0编辑  收藏  举报  来源