美文网首页
备份服务企业应用说明-rsync备份服务

备份服务企业应用说明-rsync备份服务

作者: linux_龍 | 来源:发表于2019-07-15 21:51 被阅读0次

    1.企业备份服务多模块配置

    开发人员 ---dev --- /vip
    运维人员 ---sa --- /sa
    数据库人员 ---dba --- /dba
    第一步:修改配置文件添加多模块

    [sa]
    comment = "for system admin"
    path = /sa
    [vip]
    comment = "for dev"
    path = /vip
    [dba]
    comment = "for database"
    path = /dba
    

    第二步:创建备份目录 给目录目录rsync权限

    [root@backup ~]# mkdir -p  /{sa,vip,dba}
    [root@backup ~]# chown rsync.rsync /{sa,vip,dba}
    [root@backup ~]# ll -d /{sa,vip,dba}
    drwxr-xr-x 2 rsync rsync 6 Jul 15 20:07 /dba
    drwxr-xr-x 2 rsync rsync 6 Jul 15 20:07 /sa
    drwxr-xr-x 2 rsync rsync 6 Jul 15 20:07 /vip
    

    验证

    [root@nfs /]# rsync -avz /etc/hosts rsync_backup@172.16.1.41::sa
    Password: 
    sending incremental file list
    hosts
    
    sent 221 bytes  received 43 bytes  75.43 bytes/sec
    total size is 349  speedup is 1.32
    [root@nfs /]# rsync -avz /etc/hosts rsync_backup@172.16.1.41::dba
    Password: 
    sending incremental file list
    hosts
    
    sent 221 bytes  received 43 bytes  75.43 bytes/sec
    total size is 349  speedup is 1.32
    [root@nfs /]# rsync -avz /etc/hosts rsync_backup@172.16.1.41::vip
    Password: 
    sending incremental file list
    hosts
    
    sent 221 bytes  received 43 bytes  75.43 bytes/sec
    total size is 349  speedup is 1.32
    

    2.扩展:如果统一将数据存储在一个目录中,如何进行区分不同数据是哪个用户存储的?

    环境准备: oldboy ~/oldboy.txt
    oldgirl ~/oldgirl.txt
    服务端:

    [root@backup ~]# ll /backup
    total 4
    -rw-r--r-- 1 rsync rsync 349 Jun 25 09:12 hosts
    

    客户端

    [oldboy@nfs ~]$ rsync -avz oldboy.txt rsync_backup@172.16.1.41::backup
    Password: 
    sending incremental file list
    oldboy.txt
    
    sent 120 bytes  received 43 bytes  46.57 bytes/sec
    total size is 7  speedup is 0.04
    

    服务端

    [root@backup ~]# ll /backup
    total 8
    -rw-r--r-- 1 rsync rsync 349 Jun 25 09:12 hosts
    -rw-rw-r-- 1 rsync rsync   7 Jul 17 15:08 oldboy.txt
    

    修改配置文件/etc/rsyncd.conf

    uid = root
    gid = root
    #fake super =yes
    chowm root.root /backup

    ps:备份服务器中一定要有指定存储的用户存在 多个主机的ID要保持一致

    测试
    客户端

    [oldboy@nfs ~]$ rsync -avz oldboy.txt rsync_backup@172.16.1.41::backup
    Password: 
    sending incremental file list
    oldboy.txt
    
    sent 120 bytes  received 43 bytes  65.20 bytes/sec
    total size is 7  speedup is 0.04
    
    [olgril@nfs ~]$ rsync -avz olgril.txt rsync_backup@172.16.1.41::backup
    Password: 
    sending incremental file list
    olgril.txt
    
    sent 119 bytes  received 43 bytes  46.29 bytes/sec
    total size is 7  speedup is 0.04
    

    服务端检测结果

    [root@backup ~]# ll  /backup/
    total 8
    -rw-r--r-- 1 rsync  rsync  349 Jun 25 09:12 hosts
    -rw-rw-r-- 1 oldboy oldboy   7 Jul 17 15:08 oldboy.txt
    [root@backup ~]# ll  /backup/
    total 12
    -rw-r--r-- 1 rsync  rsync  349 Jun 25 09:12 hosts
    -rw-rw-r-- 1 oldboy oldboy   7 Jul 17 15:08 oldboy.txt
    -rw-rw-r-- 1 olgril    olgril      7 Jul 17 15:19 olgril.txt
    

    3.备份数据进行排除备份

    环境准备

    [root@nfs ~]# mkdir /oldboy/{a..c}
    [root@nfs ~]# touch /oldboy/{a..c}/oldboy{01..03}.txt
    

    需求备份/oldboy整个数据,排除b目录不要同步备份 排除c目录中的oldboy03.txt文件
    排除参数
    --exclude : 排除指定单个数据信息
    --exclude-from: 排除指定多个数据信息
    ps: --exclude指定排除数据信息,目录结构必须是相对路径,相对于传输的目录而言
    第一种方法:
    客户端

    [root@nfs ~]# rsync -avz /oldboy/ --exclude=b --exclude=c/oldboy03.txt rsync_backup@172.16.1.41::backup --password-file=/etc/rsync.password
    sending incremental file list
    ./
    a/
    a/oldboy01.txt
    a/oldboy02.txt
    a/oldboy03.txt
    c/
    c/oldboy01.txt
    c/oldboy02.txt
    
    sent 378 bytes  received 134 bytes  1,024.00 bytes/sec
    total size is 0  speedup is 0.00
    

    服务端

    [root@backup /backup]# tree /backup 
    /backup
    ├── a
    │   ├── oldboy01.txt
    │   ├── oldboy02.txt
    │   └── oldboy03.txt
    └── c
        ├── oldboy01.txt
        └── oldboy02.txt
    
    2 directories, 5 files
    

    第二种方法:
    客户端

    [root@nfs ~]# vi /oldboy/exclude.txt
    b/oldboy01.txt
    b/oldboy02.txt
    c/oldboy01.txt
    c/oldboy02.txt
    
    [root@nfs ~]# rsync -avz /oldboy/ --exclude-from=/oldboy/exclude.txt rsync_backup@172.16.1.41::backup --password-file=/etc/rsync.password
    sending incremental file list
    ./
    exclude.txt
    a/
    a/oldboy01.txt
    a/oldboy02.txt
    a/oldboy03.txt
    b/
    b/oldboy03.txt
    c/
    c/oldboy03.txt
    
    sent 507 bytes  received 161 bytes  1,336.00 bytes/sec
    total size is 61  speedup is 0.09
    

    服务端

    [root@backup /backup]# tree /backup 
    /backup
    ├── a
    │   ├── oldboy01.txt
    │   ├── oldboy02.txt
    │   └── oldboy03.txt
    ├── b
    │   └── oldboy03.txt
    ├── c
    │   └── oldboy03.txt
    └── exclude.txt
    
    3 directories, 6 files
    

    4.企业备份服务创建多级目录(一级一级创建,不能一次性创建多级目录)

    需求:
    sa /sa
    sa01 /sa/sa01/scripts
    /conf
    sa02 /sa/sa02/
    sa03 /sa/sa03/
    dev /devop
    dba /dba
    客户端

    [root@nfs ~]# rsync -avz /oldboy/ rsync_backup@172.16.1.41::backup/sa/
    Password: 
    sending incremental file list
    created directory sa
    ./
    exclude.txt
    a/
    a/oldboy01.txt
    a/oldboy02.txt
    a/oldboy03.txt
    b/
    b/oldboy01.txt
    b/oldboy02.txt
    b/oldboy03.txt
    c/
    c/oldboy01.txt
    c/oldboy02.txt
    c/oldboy03.txt
    
    sent 715 bytes  received 262 bytes  217.11 bytes/sec
    total size is 61  speedup is 0.06
    

    服务端

    #5.企业备份数据访问控制
    [root@backup /backup]# tree /backup
    /backup
    └── sa
        ├── a
        │   ├── oldboy01.txt
        │   ├── oldboy02.txt
        │   └── oldboy03.txt
        ├── b
        │   ├── oldboy01.txt
        │   ├── oldboy02.txt
        │   └── oldboy03.txt
        ├── c
        │   ├── oldboy01.txt
        │   ├── oldboy02.txt
        │   └── oldboy03.txt
        └── exclude.txt
    

    4 directories, 10 files
    hosts allow = 172.16.1.0/24 --- 允许172.16.1.0网段主机存储数据 172.16.1.31 10.0.0.31
    hosts deny = 0.0.0.0/32 --- 阻止0.0.0.0地址主机存储数据
    备份服务配置文件中:全局配置 局部配置
    全局配置:在模块之上配置都是全局配置 可以影响所有模块
    局部配置:在模块中的配置都是局部配置 可以影响指定模块
    PS:局部配置优先于全局配置

    image.png

    5.企业备份数据模块列表功能

    不知道企业中的备份模块信息.通过命令获取备份模块信息
    客户端

    修改配置文件/etc/rsyncd.conf
    list = false --- 如果改为true,客户端可以列表显示服务端详细模块信息

    服务端

    [root@nfs ~]# rsync -avz rsync_backup@172.16.1.41::
    backup          "backup dir by oldboy"
    sa              "for system admin"
    vip             "for dev"
    dba             "for database"
    

    6.企业应用无差异同步

    --delete: 保证客户端和服务端数据高度一致
    服务端
    快速清空删除目录数据:rm -f xxx
    客户端

    [root@backup /backup]# mkdir 666
    [root@backup /backup]# ll
    total 0
    drwxr-xr-x 2 root root 6 Jul 17 18:17 666
    

    服务端

    [root@nfs /null]# ll
    total 0
    [root@nfs /null]# rsync -avz --delete /null/  172.16.1.41:/backup
    root@172.16.1.41's password: 
    sending incremental file list
    deleting 666/
    ./
    sent 47 bytes  received 27 bytes  29.60 bytes/sec
    total size is 0  speedup is 0.00
    

    客户端

    [root@backup /backup]# ll
    total 0
    

    扩展

     创建50个10M的文件
    [root@nfs ~]# dd if=/dev/zero of=/tmp/500M bs=10M count=50
    50+0 records in
    50+0 records out
    524288000 bytes (524 MB) copied, 6.74511 s, 77.7 MB/s
    [root@nfs ~]# ll -h /tmp/500M
    -rw-r--r-- 1 root root 500M Jul 21 14:14 /tmp/500M
    
    p保持权限不变
    P显示传输过程
    [root@nfs ~]# rsync -avzP /tmp/500M rsync_backup@172.16.1.41::backup --password-file=/etc/rsync.password
    sending incremental file list
    500M
        524,288,000 100%  167.21MB/s    0:00:02 (xfr#1, to-chk=0/1)
    rsync: mkstemp ".500M.5gsqT8" (in backup) failed: Permission denied (13)
    
    sent 509,968 bytes  received 120 bytes  145,739.43 bytes/sec
    total size is 524,288,000  speedup is 1,027.84
    rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1178) [sender=3.1.2]
    

    7.企业传输数据扩展应用

    port = 874 端口号发生改变

    [root@nfs ~]# rsync -avzP /tmp/500M rsync_backup@172.16.1.41::backup --password-file=/etc/rsync.password --port 874
    sending incremental file list
    500M
        524,288,000 100%  142.73MB/s    0:00:03 (xfr#1, to-chk=0/1)
    rsync: mkstemp ".500M.jqzjyx" (in backup) failed: Permission denied (13)
    
    sent 509,968 bytes  received 120 bytes  113,352.89 bytes/sec
    total size is 524,288,000  speedup is 1,027.84
    rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1178) [sender=3.1.2]
    

    8.服务端配置文件保存路径不正确

    rsync --daemon [OPTION]...
    --address=ADDRESS bind to the specified address 指定监听地址
    --bwlimit=RATE limit socket I/O bandwidth 指定传输速率(错误案例)
    人人网 某一时刻带宽不足了 开发人员 --- 服务器(上传开发代码)
    每个连接进行限速
    -config=FILE specify alternate rsyncd.conf file 指定配置文件
    -M, --dparam=OVERRIDE override global daemon config parameter
    --no-detach do not detach from the parent
    --port=PORT listen on alternate port number 指定监听发端口

    备份服务优点缺点:
    优点:实现增量备份数据
    缺点:在同步大量小文件 容易造成数据丢失 (将目录进行压缩处理)
    在同步大文件数据 容易造成数据传输中断 断点续传功能不强 FTP 数据--流媒体(视频 音频) 图片

    相关文章

      网友评论

          本文标题:备份服务企业应用说明-rsync备份服务

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