rsync+inotify

һ������

    192.168.10.2�ϵ�/dataĿ¼�µ����Ҫͬ�����ݵ�192.168.10.5��/data


��������

1��192.168.10.5

    1)����װrsync������

    yum -y install rsync


    vim /etc/xinetd.d/rsync

    service rsync

    {

            disable = no

            flags           = IPv6

            socket_type     = stream

            wait            = no

            user            = root

            server          = /usr/bin/rsync

            server_args     = --daemon

            log_on_failure  += USERID

    }


    vim  /etc/rsync/rsyncd.conf

    uid = root

    gid = root

    use chroot = false

    read only = false

    hosts allow=192.168.10.0/255.255.255.0

    hosts deny=*

    max connections = 8

    pid file = /var/run/rsyncd.pid

    lock file = /var/run/rsync.lock

    log file = /var/log/rsync.log

    transfer logging = yes

    log format = %t %a %m %f %b

    syslog facility = daemon

    timeout = 20

    [data]

    path = /data

    list=no

    comment = backup_data

    auth users = backup

    secrets file = /etc/rsync/rsyncd.passwd

    strict modes = true

    ignore errors = true


    2�������������ļ�

    echo "backup:backup@123" > /etc/rsync/rsyncd.passwd

    chmod 600 /etc/rsync/rsyncd.passwd


    3��������rsync����

    usr/bin/rsync --daemon --config=/etc/rsync/rsyncd.conf


2��192.168.10.2 ����

    1����inotify��װ

    tar xf inotify-tools-3.14.tar.gz

    cd inotify-tools-3.14

    ./configure --prefix=/usr/local/services/inotify-3.14

    make && make install

    cd /usr/local/services

    ln -sf inotify-3.14 inotify


    2������ؽű�

    vim inotify.sh

    #!/bin/bash

    host=192.168.10.5  #��������ip

    src=/data/        #���ؼ��Ŀ¼

    dst=data         #����������rsync��ģ��

    user=backup      #���������rsync����������û�

    rsync_passfile=/usr/local/services/rsyncd.passwd   #���ص���rsync����������ļ���ֻ�����룩

    inotify_home=/usr/local/services/inotify    #inotify�İ�װĿ¼


    if [ ! -e "$src" ] || [ ! -e "${rsync_passfile}" ] \

        || [ ! -e "${inotify_home}/bin/inotifywait" ] || [ ! -e "/usr/bin/rsync" ];then

        echo "Check File and Folder"

    exit 9

    fi

    ${inotify_home}/bin/inotifywait -mrq --timefmt '%y/%m/%d %H:%M' --format '%T %w%f' -e modify,attrib,moved_to,move,create,delete,unmount,close_write,moved_from,delete_self $src \

| while read file

do

    cd $src && rsync -aruz -R --delete ./  --timeout=5  $user@$host::$dst --password-file=${rsync_passfile} >/dev/null 2>&1

    done

    exit 0


    3�������������ļ�

    echo "backup@123" > /usr/local/services/rsyncd.passwd

    chmod 600 /usr/local/services/rsyncd.passwd


    4)����̨���нű�

    /usr/local/services/inotify.sh &

你可能感兴趣的:(rsync+inotify)