美文网首页
2019-08-13 rsync第二天

2019-08-13 rsync第二天

作者: 麟之趾a | 来源:发表于2019-08-13 21:35 被阅读0次

rsync的原理说明

第一步

客户端====>服务端:向服务端请求数据,发送认证用户信息,传输数据信息

第二步

服务端====>客户端:接收数据信息,审核认证用户,发送回复信息,要求密码信息

第三步

客户端====>服务端:返回密码信息

第四步

服务端====>客户端:发送确认信息

第五步

客户端====>服务端:用户携带数据,通过网络传输,需要对用户身份进行转换,转变为rsync(配置文件配置的uid)

第六步

服务端====>客户端:服务端接收数据,将数据放入属主和属组为rsync的备份目录,并将传输过来的数据的属主和属组改为rsync

rsync的参数说明

rsync -avz
-a (-rpltogD)
-r 递归复制目录
-p 保持复制数据的权限不变
-l 复制软连接文件,保持软连接文件属性不变
-t 保持文件的mtime不变
-o 保持文件的属主不变
-g 保持文件的属组不变
-D 保持块设备的属性不变
===========================================================================
-L 复制软链接文件时,复制源文件到目录中,但文件名还是软连接文件
--exclude  排除某个文件,当排除多个文件 写多个--exclude后面直接跟文件名
--exclude-from 排除某个文件里面的内容,把要排除的文件名写入--exclude-from 后面的文件里头
注意:--exclude和--exclude-from 排除文件名时,都是针对上一个目录的相对路径排除
-v 显示过程,不显示进度
-z 以gzip的方式压缩传输
-P(大写) 显示传输过程中的进度 
--bwlimit 显示磁盘的传输的IO
--password-file 指定密码文件,免交互式
=============================================================================
[root@m01 ~]# tree ~/oldboy/
/root/oldboy/
├── oldboy01
│   ├── a.txt
│   ├── b.txt
│   └── c.txt
├── oldboy02
│   ├── a.txt
│   ├── b.txt
│   └── c.txt
├── oldboy03
│   ├── a.txt
│   ├── b.txt
│   └── c.txt
└── rsync_backup@172.16.1.41
    └── oldboy01
        └── oldboy

5 directories, 10 files

例:--exclude
[root@m01 ~]# rsync -avz ~/oldboy/ --exclude=oldboy01/ --exclude=oldboy02/a.txt rsync://rsync_backup@172.16.1.41:874/backup_dbadir --password-file=/etc/rsync.password
sending incremental file list
./
oldboy02/
oldboy02/b.txt
oldboy02/c.txt
oldboy03/
oldboy03/a.txt
oldboy03/b.txt
oldboy03/c.txt
rsync_backup@172.16.1.41/
sent 468 bytes  received 138 bytes  1,212.00 bytes/sec
total size is 0  speedup is 0.00
例:--exclude-from
[root@m01 ~]# cat >>exculde.txt<<EOF
> oldboy01/
> oldboy02/a.txt
> EOF
[root@m01 ~]# rsync -avz ~/oldboy/ --exclude-from=exculde.txt rsync://rsync_backup@172.16.1.41:874/backup_dbadir --password-file=/etc/rsync.password
sending incremental file list
./
oldboy02/
oldboy02/b.txt
oldboy02/c.txt
oldboy03/
oldboy03/a.txt
oldboy03/b.txt
oldboy03/c.txt
rsync_backup@172.16.1.41/
sent 468 bytes  received 138 bytes  1,212.00 bytes/sec
total size is 0  speedup is 0.00

-P(大写)和--bwlimit

bwlimit.png

客户端部署过程

echo 123456> /etc/rsync.password
chmod 600 /etc/rsync.password
[root@m01 ~]# rsync -avzP -/opt/1G rsync://rsync_backup@172.16.1.41:874/backup_dbadir --password-file=/etc/rsync.password

守护进程企业应用

客户端 数据备份 服务端

客户端 数据恢复 服务端

企业应用

创建守护进程多模块

第一个里程:修改配置文件

[root@backup /backup/dba_dir]# cat /etc/rsyncd.conf 
uid = rsync
gid = rsync
port = 874
fake super = yes
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
ignore errors
read only = false
list = false
hosts allow = 172.16.1.0/24
auth users = rsync_backup
secrets file = /etc/rsync.password
exclude = oldboy01/a.txt
[backup_sadir]
comment = "backup dir by oldboy"
path = /backup/sa_dir
[backup_dbadir]
comment = "backup dir by oldboy"
path = /backup/dba_dir
[backup_devdir]
comment = "backup dir by oldboy"
path = /backup/dev_dir

第二个里程:创建目录和修改目录属主

[root@backup /backup/dba_dir]# ls /backup/
dba_dir  dev_dir  sa_dir
[root@backup /backup/dba_dir]# chown rsync.rsync -R /backup

第三个里程:重启服务

[root@backup /backup/dba_dir]# systemctl restart rsyncd

企业应用:排除功能

同上的参数的--exclude和--exclude-from

企业应用:保证存储服务器和备份服务器数据一致
--delete参数

[root@m01 ~]# rsync -avzP  --delete oldboy/  rsync://rsync_backup@172.16.1.41:874/backup_dbadir --password-file=/etc/rsync.password
sending incremental file list
deleting oldboy/rsync_backup@172.16.1.41/oldboy01/oldboy
deleting oldboy/rsync_backup@172.16.1.41/oldboy01/
deleting oldboy/rsync_backup@172.16.1.41/
deleting oldboy/oldboy03/c.txt
deleting oldboy/oldboy03/b.txt
deleting oldboy/oldboy03/a.txt
deleting oldboy/oldboy03/
deleting oldboy/oldboy02/c.txt
deleting oldboy/oldboy02/b.txt
deleting oldboy/oldboy02/a.txt
deleting oldboy/oldboy02/
deleting oldboy/oldboy01/c.txt
deleting oldboy/oldboy01/b.txt
deleting oldboy/oldboy01/a.txt
deleting oldboy/oldboy01/
deleting oldboy/
deleting 1G
./
oldboy01/
oldboy01/a.txt
              0 100%    0.00kB/s    0:00:00 (xfr#1, to-chk=10/16)
oldboy01/b.txt
              0 100%    0.00kB/s    0:00:00 (xfr#2, to-chk=9/16)
oldboy01/c.txt
              0 100%    0.00kB/s    0:00:00 (xfr#3, to-chk=8/16)
oldboy02/a.txt
              0 100%    0.00kB/s    0:00:00 (xfr#4, to-chk=7/16)
rsync_backup@172.16.1.41/oldboy01/
rsync_backup@172.16.1.41/oldboy01/oldboy
              3 100%    0.00kB/s    0:00:00 (xfr#5, to-chk=0/16)
sent 642 bytes  received 567 bytes  2,418.00 bytes/sec
total size is 3  speedup is 0.00

企业应用:rsync的访问策略

rsync访问策略说明.jpg


全局配置:在模块上面的所有信息称为全局配置,会影响所有模块
局部配置:在单个模块上配置,称为局部配置,会影响单个模块
企业应用:守护进程创建子目录

 rsync -avzP  oldboy/  rsync://rsync_backup@172.16.1.41:874/backup/oldboy --password-file=/etc/rsync.password
#即在模块底下新增子目录传输

守护进程列表功能(了解)

cat /etc/rsyncd.conf
list = false    不允许列出模块列表
[root@m01 ~]# rsync rsync://rsync_backup@172.16.1.41:874
===============================================================================
cat /etc/rsyncd.conf
list = true    允许列出模块列表
[root@m01 ~]# rsync rsync://rsync_backup@172.16.1.41:874
backup          "backup dir by oldboy"
backup_sadir    "backup dir by oldboy"
backup_dbadir   "backup dir by oldboy"
backup_devdir   "backup dir by oldboy"

相关文章

网友评论

      本文标题:2019-08-13 rsync第二天

      本文链接:https://www.haomeiwen.com/subject/tixijctx.html