05.04 rsync备份服务章节

第一章 rsync服务器只是大纲

理解备份服务器在架构中重要性
初步理解rsync命令概念说明。
掌握rsync命令作用特点
掌握rsync命令的四种工作方式(rsync命令等价ls rm scp cp)
掌握rsync命令增量同步原理说明(老版本是先比对再传输,新版本是边比对边传输)
掌握集群架构中数据备份方式(定时同步与实时同步)
掌握rsync命令的常用参数信息
掌握rsync守护进程传输模式部署搭建过程
掌握rsync守护进程客户端访问服务器端原理
掌握rsync守护进程多模块配置方式
掌握rsync排除功能使用方式
掌握rsync无差异同步方式
掌握rsync限速传输数据方式
了解rsync服务的优缺点
掌握rsync服务的排错思路
rsync列表功能扩展说明
完成利用rsync服务全网备份方案


第二章 什么是rsync?

Rsync是一款开源的、快速的、多功能的、可实现全量及增量的本地或远程数据同步备份的优秀工具。并且可以不进行改变原有数据的属性信息,实现数据的备份迁移特性。Rsync软件适用于unix、Linux、Windows等多种操作系统平台。


第三章 rsync的四种工作方式

1. 等同于ls命令

[root@lb01-5 ~]# rsync anaconda-ks.cfg 
-rw-------        1537 2017/07/12 12:07:40 anaconda-ks.cfg

2. 等同于cp命令

[root@lb01-5 ~]# rsync -rP test.txt a.txt
sending incremental file list
test.txt
           0 100%    0.00kB/s    0:00:00 (xfer#1, to-check=0/1)

sent 70 bytes  received 31 bytes  202.00 bytes/sec
total size is 0  speedup is 0.00

[root@lb01-5 ~]# ll
total 4
-rw-------. 1 root root 1537 Jul 12 12:07 anaconda-ks.cfg
-rw-r--r--  1 root root    0 Jul 13 11:41 a.txt
-rw-r--r--  1 root root    0 Jul 13 11:41 test.txt

3. 等同于scp命令

[root@lb01-5 ~]# rsync -avrP oldboy.txt 10.0.0.8:/tmp/
The authenticity of host '10.0.0.8 (10.0.0.8)' can't be established.
ECDSA key fingerprint is 6a:13:29:66:90:80:42:bf:4d:43:c4:95:a1:24:dd:df.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.8' (ECDSA) to the list of known hosts.
root@10.0.0.8's password: 
sending incremental file list
oldboy.txt
           0 100%    0.00kB/s    0:00:00 (xfer#1, to-check=0/1)

sent 74 bytes  received 31 bytes  23.33 bytes/sec
total size is 0  speedup is 0.00


[root@backup ~]# scp -rp oldboy 10.0.0.31:/tmp/
root@10.0.0.31's password: 
b                                                              100%    0     0.0KB/s   00:00    
a                                                              100%    0     0.0KB/s   00:00    
c  
[root@nfs01 ~]# ls /tmp/oldboy/
a  b  c

4. 等同于rm命令

[root@backup ~]# rsync -r --delete oldboy/ /tmp/
[root@backup ~]# ll /tmp/
total 0
注释:这里的删除--delete相当于实时同步 同步oldboy目录下面的内容到/tmp目录下

第四章 Rsync软件服务工作常见应用

1. 定时任务+rsync方式
全网数据备份方案(备份,验证,通知)
备份服务器单点问题(多个备份服务器 同城灾备 异地灾备)

2. 实时同步+rsync方式
用户上传的数据信息,进行实时的备份


第五章 rsync工作方式

1. 本地复制方式

[root@lb01-5 ~]# rsync -rP test.txt a.txt
sending incremental file list
test.txt
           0 100%    0.00kB/s    0:00:00 (xfer#1, to-check=0/1)

sent 70 bytes  received 31 bytes  202.00 bytes/sec
total size is 0  speedup is 0.00

[root@lb01-5 ~]# ll
total 4
-rw-------. 1 root root 1537 Jul 12 12:07 anaconda-ks.cfg
-rw-r--r--  1 root root    0 Jul 13 11:41 a.txt
-rw-r--r--  1 root root    0 Jul 13 11:41 test.txt

2. 隧道传输方式

[root@backup ~]# rsync -avzP /etc/hosts root@10.0.0.31:/tmp/
root@10.0.0.31's password: 
sending incremental file list
hosts
         321 100%    0.00kB/s    0:00:00 (xfer#1, to-check=0/1)

sent 199 bytes  received 31 bytes  65.71 bytes/sec
total size is 321  speedup is 1.40

[root@nfs01 ~]# ll /tmp/
total 4
-rw-r--r-- 1 root root 321 May  3 16:21 hosts
[root@backup ~]# rsync -avzP -e "ssh -p 22" /etc/passwd root@10.0.0.31:/tmp/
root@10.0.0.31's password: 
Permission denied, please try again.
root@10.0.0.31's password: 
sending incremental file list
passwd
        1140 100%    0.00kB/s    0:00:00 (xfer#1, to-check=0/1)

sent 534 bytes  received 31 bytes  66.47 bytes/sec
total size is 1140  speedup is 2.02

[root@nfs01 ~]# ll /tmp/
total 8
-rw-r--r-- 1 root root  321 May  3 16:21 hosts
-rw-r--r-- 1 root root 1140 May  4 11:58 passwd

3. 守护进程方式

#!/bin/bash
. /etc/init.d/functions

yum install -y rsync
#创建rsync配置文件
echo "##rsyncd.conf start##
uid = rsync
gid = rsync
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[backup]
path = /backup
ignore errors
read only = false
list = false
hosts allow = 172.16.1.0/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
" >/etc/rsyncd.conf

#添加rsync虚拟用户
useradd -s /sbin/nologin -M rsync

#创建/backup目录并修改权限
mkdir /backup  /data -p && chown -R rsync.rsync /backup/  

#创建用户密码文件并更改权限
echo "rsync_backup:123456" >/etc/rsync.password  && chmod 600 /etc/rsync.password

#启动守护进程 并加入开机自启动
rsync --daemon && echo "rsync --daemon" >>/etc/rc.local 

#启动rsync守护进程服务
rsync --daemon

#客户端测试
[root@web02-8 ~]# rsync -avzP awkfile.txt rsync_backup@10.0.0.7::backup
Password: 
sending incremental file list
awkfile.txt
         105 100%    0.00kB/s    0:00:00 (xfer#1, to-check=0/1)

sent 133 bytes  received 27 bytes  45.71 bytes/sec
total size is 105  speedup is 0.66


第六章 rsync服务优缺点总结

1. Rsync优点

   增量备份,支持socket(daemon),集中备份(支持维拉,都是以客户端为参照物)。
   远程SHELL通道模式还可以加密(ssh)传输
   socket(daemon)需要加密传输,可以利用VPN服务或ipsec服务。

2. Rsync缺点


   大量小文件实时同步的时候,比对时间较长,有的时候同步过程中,rsync进程可能会停止,僵死
   同步大文件,10G这样的大文件有时也会有问题,中断。未完整同步前,是隐藏文件,可以通过续传(--partial)等参数实现传输。
   一次性远程拷贝可以用scp,大量小文件要打包成一个包再拷贝。

第七章 Rsync案例练习

1. 客服端从服务端/backup目录下拉去文件到本地/tmp目录下

[root@web02-8 ~]# rsync -avzP rsync_backup@10.0.0.7::backup /tmp/ --password-file=/etc/rsync.password
receiving incremental file list
./
chao.txt
           0 100%    0.00kB/s    0:00:00 (xfer#1, to-check=0/3)

sent 86 bytes  received 191 bytes  554.00 bytes/sec
total size is 105  speedup is 0.38

2. 客服端/tmp下文件推送到服务端/backup目录下

[root@web02-8 ~]# rsync -avzP /tmp/ rsync_backup@10.0.0.7::backup --password-file=/etc/rsync.password
sending incremental file list
./
awkfile.txt
         105 100%    0.00kB/s    0:00:00 (xfer#1, to-check=12/14)
chao.txt
           0 100%    0.00kB/s    0:00:00 (xfer#2, to-check=11/14)
hosts
         158 100%  154.30kB/s    0:00:00 (xfer#3, to-check=10/14)
ks-script-zUioEz
         836 100%  408.20kB/s    0:00:00 (xfer#4, to-check=9/14)
oldboy.txt
           0 100%    0.00kB/s    0:00:00 (xfer#5, to-check=8/14)
yum.log
           0 100%    0.00kB/s    0:00:00 (xfer#6, to-check=7/14)
.ICE-unix/
.Test-unix/
.X11-unix/
.XIM-unix/
.font-unix/
systemd-private-7f586753fef140e88abcaddff295b84b-vmtoolsd.service-sQo0wn/
systemd-private-7f586753fef140e88abcaddff295b84b-vmtoolsd.service-sQo0wn/tmp/

sent 1164 bytes  received 153 bytes  2634.00 bytes/sec
total size is 1099  speedup is 0.83

3. 客户端同步到服务端并排除某两个文件

[root@web02-8 ~]# rsync -avzP --exclude={awkfile.txt,chao.txt} /tmp/ rsync_backup@10.0.0.7::backup --password-file=/etc/rsync.password
sending incremental file list
./
hosts
         158 100%    0.00kB/s    0:00:00 (xfer#1, to-check=10/12)
ks-script-zUioEz
         836 100%  816.41kB/s    0:00:00 (xfer#2, to-check=9/12)
oldboy.txt
           0 100%    0.00kB/s    0:00:00 (xfer#3, to-check=8/12)
yum.log
           0 100%    0.00kB/s    0:00:00 (xfer#4, to-check=7/12)
systemd-private-7f586753fef140e88abcaddff295b84b-vmtoolsd.service-sQo0wn/
systemd-private-7f586753fef140e88abcaddff295b84b-vmtoolsd.service-sQo0wn/tmp/

sent 890 bytes  received 100 bytes  1980.00 bytes/sec
total size is 994  speedup is 1.00
[root@nfs01 tmp]# rsync -avzP --exclude-from=paichu --delete /tmp/ rsync_backup@172.16.1.41::backup --password-file=/etc/rsync.password 
sending incremental file list
./
3
           0 100%    0.00kB/s    0:00:00 (xfer#1, to-check=3/5)
paichu
           4 100%    0.00kB/s    0:00:00 (xfer#2, to-check=0/5)

sent 168 bytes  received 49 bytes  434.00 bytes/sec
total size is 4  speedup is 0.02

4. (坑坑坑)当服务端向客户端实时无差异同步时,涉及到特殊目录,会影响其权限

[root@nfs01 tmp]# ll /tmp/ -d 
drwxrwxrwt. 3 501 501 4096 May  5 16:42 /tmp/

[root@backup backup]# rsync -avzP --delete  /backup/ root@10.0.0.31:/tmp/
root@10.0.0.31's password: 
sending incremental file list
./
deleting backup/paichu
deleting backup/5
deleting backup/4
deleting backup/3
deleting backup/1
deleting backup/
1
           0 100%    0.00kB/s    0:00:00 (xfer#1, to-check=4/6)
3
           0 100%    0.00kB/s    0:00:00 (xfer#2, to-check=3/6)
4
           0 100%    0.00kB/s    0:00:00 (xfer#3, to-check=2/6)
5
           0 100%    0.00kB/s    0:00:00 (xfer#4, to-check=1/6)
paichu
           4 100%    0.00kB/s    0:00:00 (xfer#5, to-check=0/6)

sent 287 bytes  received 110 bytes  113.43 bytes/sec
total size is 4  speedup is 0.01

[root@nfs01 tmp]# ll /tmp/ -d 
drwxr-xr-x. 2 501 501 4096 May  5 16:24 /tmp/

第八章 Rsync开机自启动

1. 利用/etc/rc.local 开机自启动文件

[root@backup ~]# echo "# rsync boot info" >>/etc/rc.local 
 [root@backup ~]# echo "rsync --daemon" >>/etc/rc.local 
 [root@backup ~]# tail -2 /etc/rc.local 
 # rsync boot info
 rsync --daemon

2. 编写脚本文件

编写出脚本文件,可以利用rsync --daemon启动命令
将编写脚本文件,放置到/etc/init.d/ 目录下面
脚本内容信息要添加 # chkconfig: 2345 55 25
授予脚本执行权限
添加到chkconfig启动管理服务列表中

3. xinetd自启动rsync服务 添加到chkconfig启动管理服务列表中


第九章 集群架构服务备份方案项目

借助cron+rsync把所有客户服务器数据同步到备份服务器
全网服务器数据备份解决方案提出及负责实施200x.03 200x.09
针对公司重要数据备份混乱状况向领导提出备份全网数据的解决方案。
通过本地打包备份,然后rsync结合inotify应用把全网数据统一备份到一个固定存储服务器,然后在存储服务器上通过脚本检查并报警管理员备份结果。
定期将IDC机房的数据备份到公司的内部服务器,防止机房地震及火灾问题导致数据丢失。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值