1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
参数说明
v
:详细提示
a:以archive模式操作,复制目录、符号连接,等价于 -rlptgoD 。
z:压缩
u:只进行更新,防止本地新文件被重写,注意两者机器的时钟的同时
P:是综合了–partial –progress两个参数,
所以此时的
rsync
支持了断点续传
1、主机a启动
rsync
服务:
/usr/bin/rsync
--daemon --address=192.168.1.250
配置文件默认:
/etc/rsyncd
.conf
没有这个配置可以自己写一个
----
uid = nobody
gid = nobody
use chroot = no
max connections = 10
timeout = 600
pid
file
=
/var/run/rsyncd
.pid
lock
file
=
/var/run/rsyncd
.lock
log
file
=
/var/log/rsyncd
.log
[模块名a]
path = 目录
/a/b/c
read
only =
yes
list = no
hosts allow = 允许的ip,最好是内网
hosts deny = *
uid = root
gid = root
----
注意,使用list = no 否则可以直接通过
rsync
ip:: 列出模块名
2、主机b同步主机a
rsync
--avzP ipa::模块名a 目录
/x/y/z
注意::和:的区别, 目录最后有没有斜杠的区别。
3、注意测试src 和 dest 路径对应的文件夹是否符合预期;例如上述例子是将
/a/b/c
同步到本地的
/x/y/z
目录z下面放的是目录c,并非是c目录下的文件,即:
/x/y/z/c/
刚测试了下,如果路径a配置的是
/a/b/c/
则同步的是
/x/y/z/
(c目录下的文件)
也就是要注意路径最后有没有斜杠/
测试用例:
~]$
mkdir
d{1,2}/{a,b,c} -p
~]$
ls
d1 d2
~]$
rsync
d1 d2
skipping directory d1
~]$
rsync
-avzP d1 d2
sending incremental
file
list
d1/
d1
/a/
d1
/b/
d1
/c/
sent 96 bytes received 28 bytes 248.00 bytes
/sec
total size is 0 speedup is 0.00
~]$ tree d2
d2
├── a
├── b
├── c
└── d1
├── a
├── b
└── c
7 directories, 0 files
~]$
rsync
-avzP d1/ d2/
sending incremental
file
list
./
sent 78 bytes received 18 bytes 192.00 bytes
/sec
total size is 0 speedup is 0.00
~]$
rsync
-avzP --delete d1/ d2/
sending incremental
file
list
deleting d1
/c/
deleting d1
/b/
deleting d1
/a/
deleting d1/
sent 75 bytes received 15 bytes 180.00 bytes
/sec
total size is 0 speedup is 0.00
~]$ tree d2
d2
├── a
├── b
└── c
3 directories, 0 files
4、限速
GB级别的网卡,调整限速为600Mbps = 60000KBps
# rsync -avzP --delete --bwlimit=60000 192.168.1.250::upload /home/web/upload >/dev/null
http:
//drops
.wooyun.org
/papers/161
5、
rsync
和inotifywait的排除选项
#!/bin/bash
#
# rsync -avzP --exclude="*.log" --exclude="*.zip.*" --exclude="*.csv.*" --exclude="*.xls.*" /home/web/log/exportlog/ 192.168.5.72::s72log_export_pub
src=
/home/web/log/exportlog/
dest=s72log_export_pub
ip=192.168.5.72
/usr/local/bin/inotifywait
-mr -e close_write --exclude
'^.*(log|csv\..*|xls\..*|zip\..*)$'
$src |
while
read
file
do
echo
"[+] `date` start"
echo
"[-] $file"
rsync
-avzP --exclude=
"*.log"
--exclude=
"*.zip.*"
--exclude=
"*.csv.*"
--exclude=
"*.xls.*"
$src $ip::$dest
echo
"[-] `date` end"
done
6、注意
rsync
排除目录的区别
# rsync -avP --delete 192.168.1.50:/media/ /mnt/ --exclude="boot"
# rsync -avP --delete 192.168.1.50:/media/ /mnt/ --exclude="/boot"
# rsync -avP --delete 192.168.1.50:/media/ /mnt/ --exclude="boot/"
# rsync -avP --delete 192.168.1.50:/media/ /mnt/ --exclude="/boot/"
7、如果使用 -z 参数,则可能导致传输速度变慢
8、使用密码验证
服务端:
# cat /etc/rsyncd.conf
-----
uid = root
gid = root
use chroot =
yes
max connections = 200
timeout=600
#syslog facility = local5
pid
file
=
/var/log/rsync/rsyncd
.pid
log
file
=
/var/log/rsync/rsyncd
.log
lock
file
=
/var/log/rsync/rsync
.lock
[data]
path =
/data
refuse options = delete
comment = backup
read
only= no
uid = root
gid = root
#ignore errors
auth
users
= backup
secrets
file
=
/etc/rsyncd
.secrets
-----
# cat /etc/rsyncd.secrets
backup:111111
# chmod 600 /etc/rsyncd.secrets
# /usr/bin/rsync --daemon --address=192.168.1.100
客户端:
# cat /etc/rsync.pass
111111
# chmod 600 /etc/rsync.pass
# rsync -av --no-o --no-g --password-file=/etc/rsync.pass /tmp/1 backup@192.168.1.100::data/backup/ovirt/engine
|
本文转自 pcnk 51CTO博客,原文链接:http://blog.51cto.com/nosmoking/1595639,如需转载请自行联系原作者