设为首页 收藏本站
查看: 292|回复: 0

[经验分享] rsync镜像同步

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-3-31 10:05:25 | 显示全部楼层 |阅读模式
环境: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 ~]#




备份脚本: spacer.jpg
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)


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-198115-1-1.html 上篇帖子: Linux目录结构剖析说明 下篇帖子: linux修改中文显示
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表