期中架构之==Rsync常用命令和案例

一、Rsync常用参数

1.常用参数

-a      #归档模式传输, 等于-tropgDl -t -r -o -p -g -D -l   ******
-v      #详细模式输出, 打印速率, 文件数量等   ******
-z      #传输时进行压缩以提高效率   ******
-r      #递归传输目录及子目录,即目录下得所有目录都同样传输。
-t      #保持文件时间信息
-o      #保持文件属主信息
-p      #保持文件权限
-g      #保持文件属组信息
-l      #保留软连接
-P     #显示同步的过程及传输时的进度等信息
-D     #保持设备文件信息
-L     #保留软连接指向的目标文件
-e     #使用的信道协议,指定替代rsh的shell程序
--exclude=1.txt     #指定排除不需要传输的文件  *****
--exclude-from=file   #指定排除不需要传输的file下指定的文件内容(不包括file)   ******
--bwlimit=100         #限速传输   ******
--partial             #断点续传
--delete              #让目标目录和源目录数据保持一致   ******
--password-file=xxx   #使用密码文件

2.常用参数详解

#1.--exclude-from=file   排除参数

#创建多个文件
[root@web01 ~]# touch {1..10}.txt
[root@web01 ~]# ll
总用量 12
-rw-r--r--  1 root root    0 4月  28 07:29 10.txt
-rw-r--r--  1 root root    0 4月  28 07:29 1.txt
-rw-r--r--  1 root root    0 4月  28 07:29 2.txt
-rw-r--r--  1 root root    0 4月  28 07:29 3.txt
-rw-r--r--  1 root root    0 4月  28 07:29 4.txt
-rw-r--r--  1 root root    0 4月  28 07:29 5.txt
-rw-r--r--  1 root root    0 4月  28 07:29 6.txt
-rw-r--r--  1 root root    0 4月  28 07:29 7.txt
-rw-r--r--  1 root root    0 4月  28 07:29 8.txt
-rw-r--r--  1 root root    0 4月  28 07:29 9.txt

#编辑要指定的排除文件内容
[root@web01 ~]# vim a.txt
1.txt
2.txt
3.txt

#指定排除文件推送内容
[root@web01 ~]# rsync -avz ./* rsync_backup@17216.1.41::backup --exclude-from
=a.txt


#2.--bwlimit=100   限速传输

#创建一个1G 文件
[root@web01 opt]# dd if=/dev/zero of=./1.txt bs=1M count=1000
记录了1000+0 的读入
记录了1000+0 的写出
1048576000字节(1.0 GB)已复制,6.9373 秒,151 MB/秒

#限速1M每秒推送
[root@web01 opt]# rsync -avzP 1.txt rsync_backup@172.16.1.41::backup --bwlimit=1
1.txt
    114,130,944 10% 1.01MB/s 0:15:06


#3.--delete 数据一致(无差异同步)

#查看客户端数据
[root@web01 opt]# rm -rf 1.txt 2.txt 3.txt 
[root@web01 opt]# ll
总用量 4
-rw-r--r-- 1 root root  0 4月  28 07:29 10.txt
-rw-r--r-- 1 root root  0 4月  28 07:29 4.txt
-rw-r--r-- 1 root root  0 4月  28 07:29 5.txt
-rw-r--r-- 1 root root  0 4月  28 07:29 6.txt
-rw-r--r-- 1 root root  0 4月  28 07:29 7.txt
-rw-r--r-- 1 root root  0 4月  28 07:29 8.txt
-rw-r--r-- 1 root root  0 4月  28 07:29 9.txt
-rw-r--r-- 1 root root 18 4月  28 07:31 a.txt

#执行数据一致同步(推送)
[root@web01 opt]# rsync -avz ./* rsync_backup@172.16.1.41::backup --delete

#查看服务端数据
[root@backup backup]# ll
总用量 4
-rw-r--r-- 1 root root  0 4月  28 07:29 10.txt
-rw-r--r-- 1 root root  0 4月  28 07:29 4.txt
-rw-r--r-- 1 root root  0 4月  28 07:29 5.txt
-rw-r--r-- 1 root root  0 4月  28 07:29 6.txt
-rw-r--r-- 1 root root  0 4月  28 07:29 7.txt
-rw-r--r-- 1 root root  0 4月  28 07:29 8.txt
-rw-r--r-- 1 root root  0 4月  28 07:29 9.txt
-rw-r--r-- 1 root root 18 4月  28 07:31 a.txt

#注意:
拉取时:客户端数据与服务端数据一致,以服务端数据为准
推送时:服务端数据一客户端数据一致,以客户端数据为准

二、Rsync备份案例

1.准备服务器

在这里插入图片描述

2.了解需求

  • 客户端需求:
    客户端提前准备存放的备份的目录,目录规则如下:/backup/nfs_172.16.1.31_2018-09-02
    客户端在本地打包备份(系统配置文件、应用配置等)拷贝至/backup/nfs_172.16.1.31_2018-09-02
    客户端最后将备份的数据进行推送至备份服务器
    客户端每天凌晨1点定时执行该脚本
    客户端服务器本地保留最近7天的数据, 避免浪费磁盘空间
  • 服务端需求:
    服务端部署rsync,用于接收客户端推送过来的备份数据
    服务端需要每天校验客户端推送过来的数据是否完整
    服务端需要每天校验的结果通知给管理员
    服务端仅保留6个月的备份数据,其余的全部删除

3.客户端操作

#1.创建备份目录 尝试获取信息
[root@web01 ~]# mkdir /backup
[root@web01 ~]# hostname
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值