zoukankan      html  css  js  c++  java
  • 第三十三天-rsync高级同步工具深度实战

    今天主要学习了rsync的两个参数--exclude和--delete 排除,下面我们来举例说明

    一、--exclude参数
    1、只排除一个文件不同步

    [root@B ~]# rsync -avz --exclude=1 rsync_backup@192.168.1.100::oldboy /data1/ --password-file=/etc/rsync.password
    receiving incremental file list
    ./
    2
    3
    4
    5
    6
    sent 169 bytes  received 350 bytes  1038.00 bytes/sec
    total size is 8  speedup is 0.02

    2、排除多个文件不同步

    方法一:
    [root@B ~]# rsync -avz --exclude={1,2} /data1/ rsync_backup@192.168.1.100::oldboy --password-file=/etc/rsync.password sending incremental file list ./ 3 4 5 6 a b 方法二: [root@B ~]# rsync -avz --exclude={1..3} /data1/ rsync_backup@192.168.1.100::oldboy --password-file=/etc/rsync.password sending incremental file list ./ 4 5 6 a b 方法三: [root@B ~]# rsync -avz --exclude=1 --exclude=2 /data1/ rsync_backup@192.168.1.100::oldboy --password-file=/etc/rsync.password sending incremental file list ./ 3 4 5 6 a b


    3、加文件,文件里的内容不同步

    [root@B ~]# cat paichu.log
    1
    2
    3
    [root@B ~]# rsync -avz --exclude-from=/root/paichu.log /data1/ rsync_backup@192.168.1.100::oldboy --password-file=/etc/rsync.password
    sending incremental file list
    ./
    4
    5
    6
    a
    b
    sent 282 bytes  received 106 bytes  776.00 bytes/sec
    total size is 8  speedup is 0.02

    4、客户端rsync命令排除小结
      排除单个文件:
      rsync -avz --exclude=1 rsync_backup@192.168.1.100::oldboy /data1/ --password-file=/etc/rsync.password

      排除多个文件:
      rsync -avz --exclude={1,2} /data1/ rsync_backup@192.168.1.100::oldboy --password-file=/etc/rsync.password
      rsync -avz --exclude=1 --exclude=2 rsync_backup@192.168.1.100::oldboy /data1/ --password-file=/etc/rsync.password
      rsync -avz --exclude={1..2} /data1/ rsync_backup@192.168.1.100::oldboy --password-file=/etc/rsync.password
      rsync -avz --exclude-from=/root/paichu.log /data1/ rsync_backup@192.168.1.100::oldboy --password-file=/etc/rsync.password

      服务端排除参数:在配置文件/etc/rsyncd.conf里面
      exclude=a b
      exclude=test/oldboy.txt

    二、无差异同步:--delete参数
    rsync推送企业工作场景:
    1、备份 --delete风险
      本地有啥,远端就有啥,本地没有的远端也要删除。服务器上的目录数据可能丢失

    rsync拉取企业工作场景:
    1、代码发布,下载。--delete风险
      远端有啥,本地就有啥,远端没有的本地有也要删除,本地的目录数据可能丢失

    rsync无差异同步的生产场景应用总结:
        一般是有需要两台服务器之间,必须要求数据一致,且时时性又不是很高的情况,如两台负载均衡下面的web服务器之间的同步,或者高可用双机配置之间的同步等,rsync无差异同步非常的危险,而且,有很多替代方案,因此,生产场景没有特殊的需求,应该避免使用。

    三、限速同步 

    1、加上限速参数 --bwlimit=10

    [root@nfs01 backup]# rsync -avz --bwlimit=10 /backup/ rsync_backup@172.16.1.41::backup/ --password-file=/etc/rsync.password
    sending incremental file list
    ./
    test1
    
    sent 130609 bytes  received 30 bytes  9009.59 bytes/sec
    total size is 134217728  speedup is 1027.39

      可以看到传输速度为9009.59byte/sec

      --bwlimit=10
      参数值的默认单位是KBPS,也就是每秒多少KB

     四、常见错误

    错误1:
    在最后带上--password-file=/cygdrive/f/mysql5.5.16/cwRsync/pwd.secrets时,提示:
    password file must not be other-accessible
    continuing without password file
    Password:
    网上答案是:WINDOW出现这种情况,是因为pwd.secrets的权限不对,或存放的位置不是NTFS分区。但二者均检验过,仍无效。
    尝试了:
    A、用/cygdrive/f...
    B、路径改成f:/和f:,
    C、把--password-file选项放前面或后面
    D、把pwd.secrets的属性安全只保留WINDOWS帐户或cwRsync,且只读。
    E、把linux其它客户端上的rsyncd.pwd拖下来给window也不行。
    四种情况均无效。有待进一步尝试。
    在linux上出现这种错误则容易解决。原因是这份客户端的密码文件必需设成调用者只读属性“600”才行。 
      
    错误2: 
    rsync: read error: Connection reset by peer (104)
    rsync error: error in rsync protocol data stream (code 12) at io.c(794) [receive
    r=3.0.2]
    解决:很大可能是服务器端没有开启 rsync 服务。开启服务。 
      
    错误3:
    @ERROR: chdir failed
    rsync error: error starting client-server protocol (code 5) at main.c(1495) [receiver=3.0.2]
    解决:服务器端同步目录没有权限,cwrsync 默认用户是Svcwrsync。为同步
    目录添加用户Svcwrsync 权限。 
      
    错误4:
    rsync: failed to connect to 210.28.93.4: No route to host (113)
    是server端口的防火墙端口没开。 
      
    错误5:
    @ERROR: chroot failed
    rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6] 
    是服务器上忘记新建目录了… 
      
    错误6:
    rsync warning: some files vanished before they could be transferred (code 24) at main.c(1039) [sender=3.0.6]
    本地文件在同步过程中被删除了。 
      
    错误7:
    rsync error: some files could not be transferred (code 23) at main.c(1385) [generator=2.6.9] 
    这是因为在服务器端的备份文件名中有非法符号,可能造成Windows同步数据时无法识别文件名。 
      
    错误8:
    @ERROR: failed to open lock file
    rsync error: error starting client-server protocol (code 5) at main.c(1495) [rec
    eiver=3.0.2]
    解决:配置文件 rsync.conf 中添加 lock file = rsyncd.lock 即可解决。 
      
    错误9:
    @ERROR: auth failed on module XXX
    出现这种情况,先检查你的用户名、密码、主机IP地址是否正确,
    如果都正确,有一个可能是原因是:远程rsync服务器的帐户密码文件的权限必须为600,例如,你在rsyncd.conf中设置了secrets file =  
    /etc/rsyncd/rsync_pwd
    那么你就必须确保rsync_pwd的访问权限为600:
    chmod 600 /etc/rsyncd/rsync_pwd
    然后你的问题可能就解决了。

    这个也不错:https://linux.cn/article-4504-1.html 

    本文源自:老男孩老师视频教程

  • 相关阅读:
    win7常用快捷键
    java中构造代码块、方法调用顺序问题
    eclipse项目改为maven项目导致svn无法比较历史数据的解决办法
    linux配置Anaconda python集成环境
    DataFrame对行列的基本操作实战
    驱动:电阻屏触摸芯片NS2009
    读书笔记:代码大全(第二版)
    资料:磁角度传感器芯片
    经验:FatFs文件系统实时写入
    笔记:CAN收发器-TJA1051T与TJA1051T/3调试总结
  • 原文地址:https://www.cnblogs.com/migongci0412/p/5068583.html
Copyright © 2011-2022 走看看