zoukankan      html  css  js  c++  java
  • 028_rync和inotify实现实时备份

    一、服务节点安装inotify-tools。

    确保系统后以下输出=>

    [root@xxxx]# ll /proc/sys/fs/inotify/
    total 0
    -rw-r--r-- 1 root root 0 Aug 23 20:02 max_queued_events
    -rw-r--r-- 1 root root 0 Aug 23 20:02 max_user_instances
    -rw-r--r-- 1 root root 0 Aug 23 20:02 max_user_watches

    (1)yum -y install inotify-tools.x86_64

    (2)配置server端的inotify监测脚本

    <1>cat /opt/zkrsync/rsyncfile.sh

    #!/bin/bash
    host_pubbak=10.0.138.136
    
    src=/data/zookeeper
    dest_pubbak=zkpub
    user=root
    
    /bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e close_write,delete,create,attrib $src 
    | while read file
    do
    /bin/rsync -vzrtopg --delete --progress $src $user@$host_pubbak::$dest_pubbak
    echo "${$(date +%Y%m%d_%H%M%S)} ${files} was rsynced" >> /tmp/rsync.log 2>&1
    done

    sh /opt/zkrsync/rsyncfile.sh &

    <2>supervisord配置

    cat /etc/supervisord.d/rsync.ini

    [program:rsync]
    command=/opt/zkrsync/rsyncfile.sh
    startsecs=3
    startretries=3
    stopsignal=QUIT
    stopasgroup=true
    stopwaitsecs=10
    user=root
    redirect_stderr=true
    stdout_logfile=/data/log/rsync/running.log
    stdout_logfile_maxbytes=50MB
    stdout_logfile_backups=10
    stderr_logfile=/data/log/rsync/error.log
    stderr_logfile_maxbytes=50MB
    stderr_logfile_backups=10

    二、客户端

    (1)rsync配置文件设置

    cat /etc/rsyncd.conf
    uid = root
    gid = root
    pid file = /var/run/rsyncd.pid
    lock file = /var/run/rsync.lock
    log file = /var/log/rsyncd.log
    [zkpub]
            path = /tmp
            comment = zk transaction log trans
            read only = no
            hosts allow = 10.0.138.152    #server端ip
            hosts deny = * 

    (2)启动rsync进程服务

    rsync --daemon --config=/etc/rsyncd.conf -v

    三、 测试

    向这个目录"/tmp/test"进行文件的增删改查操作,日志样例如下:

    sending incremental file list
    test/
    deleting test/wuwu
    
    sent 40 bytes received 12 bytes 104.00 bytes/sec
    total size is 0 speedup is 0.00
    sending incremental file list
    test/
    test/iiii
    5 100% 0.00kB/s 0:00:00 (xfer#1, to-check=0/2)
    

    测试ok没有问题。

  • 相关阅读:
    vue-自定义指令
    vue-自定义过滤器--时间
    vue-jsonp
    vue-post
    vue-get-参数
    vue-get
    vue-百度下拉列表
    C#网页授权获取微信Openid
    C#微信环境分享页面给微信好友、朋友圈
    IIS服务器同时使用多个https证书如何操作443端口
  • 原文地址:https://www.cnblogs.com/itcomputer/p/7594882.html
Copyright © 2011-2022 走看看