|
环境:CentOS 6.5
先关闭防火墙和Selinux
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| [iyunv@rsync ~]# yum -y install rsync
[iyunv@rsync ~]# mkdir /etc/rsyncd
[iyunv@rsync ~]# touch /etc/rsyncd/rsyncd.conf //rsync的主配置文件
[iyunv@rsync ~]# touch /etc/rsyncd/rsyncd.secrets //rsync的密码文件
[iyunv@rsync ~]# touch /etc/rsyncd/rsyncd.motd //rsync的服务端信息提示文件
[iyunv@rsync ~]# chmod 600 /etc/rsyncd/rsyncd.secrets
[iyunv@rsync ~]# chown root:root /etc/rsyncd/rsyncd.secrets
[iyunv@rsync ~]# useradd rsync
[iyunv@rsync ~]# useradd -g rsync yfshare
[iyunv@rsync ~]# useradd -g rsync jack
[iyunv@rsync ~]# cat /etc/rsyncd/rsyncd.secrets
yfshare:123456
jack:123456
[iyunv@rsync ~]# mkdir /rsync/input -p
[iyunv@rsync ~]# mkdir /rsync/test{1..2} -p && mkdir /rsync/test
[iyunv@rsync ~]# chown rsync:rsync /rsync/ -R
[iyunv@rsync ~]# chmod 775 /rsync/ -R
|
//启动rsync服务
1
2
| [iyunv@rsync ~]#/usr/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf
[iyunv@rsync ~]#echo '/usr/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf' >> /etc/rc.local
|
1
2
3
4
5
6
7
8
9
10
11
12
| [iyunv@rsync ~]#ps -ef|grep rsync |grep -v grep
root 2267 1 0 17:44 ? 00:00:00 /usr/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf
[iyunv@rsync ~]#
[iyunv@rsync ~]# netstat -tunlp |grep rsync
tcp 0 0 192.168.31.100:873 0.0.0.0:* LISTEN 2106/rsync
[iyunv@rsync ~]#
[iyunv@rsync ~]# /etc/init.d/rsyncd restart
Stopping rsync: [OK]
Starting rsync: [OK]
[iyunv@rsync ~]#
[iyunv@rsync ~]# chkconfig --add rsyncd
[iyunv@rsync ~]# chkconfig rsyncd on
|
//客户端配置:
1
2
3
4
5
6
7
| [iyunv@client ~]# yum -y install rsync
[iyunv@client ~]# echo '123456' > /etc/rsync.password
[iyunv@client ~]# chmod 600 /etc/rsync.password
[iyunv@client ~]# rsync --list-only --password-file=/etc/rsync.password yfshare@192.168.31.100::test_rsync //这里要配置read only = yes
drwxr-xr-x 4096 2016/02/23 23:01:40 .
drwxr-xr-x 4096 2016/02/23 23:02:00 test1
[iyunv@client ~]#
|
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
| [iyunv@client ~]# mkdir /backup
[iyunv@client ~]# rsync -auvzP --password-file=/etc/rsync.password yfshare@192.168.31.100::test_rsync /backup/
receiving incremental file list
./
test1/
test1/11.txt
0 100% 0.00kB/s 0:00:00 (xfer#1, to-check=9/12)
test1/12.txt
0 100% 0.00kB/s 0:00:00 (xfer#2, to-check=8/12)
test1/13.txt
0 100% 0.00kB/s 0:00:00 (xfer#3, to-check=7/12)
test1/14.txt
0 100% 0.00kB/s 0:00:00 (xfer#4, to-check=6/12)
test1/15.txt
0 100% 0.00kB/s 0:00:00 (xfer#5, to-check=5/12)
test1/16.txt
0 100% 0.00kB/s 0:00:00 (xfer#6, to-check=4/12)
test1/17.txt
0 100% 0.00kB/s 0:00:00 (xfer#7, to-check=3/12)
test1/18.txt
0 100% 0.00kB/s 0:00:00 (xfer#8, to-check=2/12)
test1/19.txt
0 100% 0.00kB/s 0:00:00 (xfer#9, to-check=1/12)
test1/20.txt
0 100% 0.00kB/s 0:00:00 (xfer#10, to-check=0/12)
sent 260 bytes received 601 bytes 1722.00 bytes/sec
total size is 0 speedup is 0.00
[iyunv@client ~]#
[iyunv@client ~]# ls /backup/
test1
[iyunv@client ~]# ls /backup/test1/
11.txt 12.txt 13.txt 14.txt 15.txt 16.txt 17.txt 18.txt 19.txt 20.txt
[iyunv@client ~]#
|
//如果备份服务器的备份目录下文件比rsync上多,则被删除
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| [iyunv@client test1]# touch aa{1..10}.txt
[iyunv@client test1]# ls
11.txt 13.txt 15.txt 17.txt 19.txt aa10.txt aa2.txt aa4.txt aa6.txt aa8.txt
12.txt 14.txt 16.txt 18.txt 20.txt aa1.txt aa3.txt aa5.txt aa7.txt aa9.txt
[iyunv@client test1]#
[iyunv@client test1]# rsync -auvzP --delete --password-file=/etc/rsync.password yfshare@192.168.31.100::test_rsync /backup/
receiving incremental file list
deleting test1/aa9.txt
deleting test1/aa8.txt
deleting test1/aa7.txt
deleting test1/aa6.txt
deleting test1/aa5.txt
deleting test1/aa4.txt
deleting test1/aa3.txt
deleting test1/aa2.txt
deleting test1/aa10.txt
deleting test1/aa1.txt
test1/
sent 67 bytes received 238 bytes 610.00 bytes/sec
total size is 0 speedup is 0.00
[iyunv@client test1]# ls
11.txt 12.txt 13.txt 14.txt 15.txt 16.txt 17.txt 18.txt 19.txt 20.txt
[iyunv@client test1]#
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| [iyunv@client ~]# cd /backup/test1/
[iyunv@client test1]# touch bb{1..10}.txt
[iyunv@client ~]# cd /backup
[iyunv@client backup]# mkdir firefox
[iyunv@client backup]# touch firefox/fire{1..10}.txt
[iyunv@client backup]# cd
[iyunv@client ~]# rsync -auvzP --password-file=/etc/rsync.password yfshare@192.168.31.100::test_rsync /backup/
receiving incremental file list
./
sent 68 bytes received 405 bytes 946.00 bytes/sec
total size is 0 speedup is 0.00
[iyunv@client ~]# ls /backup/
firefox input test1
[iyunv@client ~]#
|
//上传文件到rsync服务端
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| [iyunv@client ~]# rsync -avSH /backup/test1/bb* yfshare@192.168.31.100::input_rsync
Password:
sending incremental file list
bb1.txt
bb10.txt
bb2.txt
bb3.txt
bb4.txt
bb5.txt
bb6.txt
bb7.txt
bb8.txt
bb9.txt
sent 517 bytes received 198 bytes 286.00 bytes/sec
total size is 0 speedup is 0.00
[iyunv@client ~]#
|
备份脚本:
1
2
3
| [iyunv@client ~]# crontab -l
0 * * * * /bin/sh /root/backup_rsync.sh
[iyunv@client ~]#
|
参数说明:
-a 相当于-rlptgoD,-r是递归 -l是链接文件,意思是拷贝链接文件;-p表示保持文件原有权限;-t保持文件原有时间;-g保持文件原有用户组;-o 保持文件原有属主;-D 相当于块设备文件;
-u, --update 仅仅进行更新,也就是跳过所有已经存在于DST,并且文件时间晚于要备份的文件。(不覆盖更新的文件)
-z 传输时压缩;
-P 传输进度;
-v 传输时的进度等信息,和-P有点关系,自己试试。
--delete 表示客户端的数据要与服务器端完全一致,如果客户端目录里有服务器上不存在的文件,则删除。
rsync的启动脚本.zip
(843 Bytes, 下载次数: 0)
rsync配置文件.zip
(739 Bytes, 下载次数: 0)
rsync备份脚本.zip
(490 Bytes, 下载次数: 0)
|
|
|