zoukankan      html  css  js  c++  java
  • rsync实现同步

    一、备份客户端:

    1.创建/etc/rsyncd.secrets 权限配置600 (写服务器端的账户密码)

    2.客户端配置文件:

    port=873
    log file=/var/log/rsync.log
    pid file=/var/run/rsync.pid
    hosts allow =172.16.16.231
    hosts deny=*

    [backup]           
    path=/databackup                (本机的备份用的文件夹)
    use chroot=yes 
    max nonections=4
    read only=no
    list=yes
    uid=root
    gid=root
    #auth users=root
    secrets file=/etc/rsyncd.secrets

    启动rsync :  rsync --daemon --config=/etc/rsyncd.conf

    备份服务端

    创建/etc/rsyncd.secrets 权限配置600 (写服务器端的账户密码)

    服务端配置文件:

    port=873
    log file=/var/log/rsync.log
    pid file=/var/run/rsync.pid
    hosts allow=172.16.16.160
    hosts deny=*
    [abc]
    path=/databakup                  (本机的要备份用的文件夹)
    use chroot=yes
    max nonections=4
    read only=no
    list=yes
    uid=root
    gid=root
    auth users=root
    secrets file=/etc/rsyncd.secrets

    安装inotify

    1)、1234 tar-zxvf inotify-tools-3.14.tar.gz
    2)、cdinotify-tools-3.14
    3)、./configure--prefix=/usr/local/inotify
    4)、make;makeinstall

    同步脚本:

    #!/bin/bash
    SRC=/databakup/exam
    SRC2=/databkup/dspbak
    #SRC=/test/test1
    #SRC2=/test/test2
    HOST=172.16.16.160
    /usr/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $SRC | while read files
    do
    /usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/rsyncd.secrets $SRC root@$HOST::backup
    done
    ~

    备份一个文件只能写一条语句

    [root@web ~]# chmod u+x /root/shell/rsync.sh

    [root@web ~]# setsid /root/shell/rsync.sh &

    #后台运行脚本,关闭shell终端继续后台运行

    rsync.sh脚本加入开机启动项

    # echo "/root/shell/rsync.sh" >> /etc/rc.local

    防火墙开启rsync端口:873

    添加:

    iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 873 -jACCEPT

    防火墙这关要慎重,有些服务器是不允许打开的

    重启:

    # /etc/init.d/iptables restart

  • 相关阅读:
    小写数字转化为大写工具类
    java中关于日期类Calendar的简单使用
    ArrayList用法总结
    滚动条(附:定时调用)
    百度Echarts的使用总结
    Datatables 使用总结
    字符串(String、StringBuffer、StringBuilder)
    sqlserver 脚本方式导出数据到excel
    前端面试
    数据库面试
  • 原文地址:https://www.cnblogs.com/jtlin/p/6023700.html
Copyright © 2011-2022 走看看