Rsync實現主機間實時備份文件

#!/usr/bin/env bash

# yum install -y inotify-tools rsync xinetd

# ------ /etc/rsyncd.conf -------
# uid=root
# gid=root
# use chroot=no
# max connections=10
# timeout=600
# strict modes=yes
# port=873
# pid file=/var/run/rsyncd.pid
# lock file=/var/run/rsyncd.lock
# log file=/var/log/rsyncd.log

# [jijin_static]
# path=/var/www/static
# comment=rsync test logs
# auth users=admin
# uid=admin
# gid=admin
# secrets file=/etc/rsyncd.secrets
# read only=no
# list=yes
# hosts allow=10.10.10.10

# ------- /etc/rsyncd.secrets -------
# admin:password

# ------ /etc/rsync_client.pwd --------
# password

# chmod 600 /etc/rsync_client.pwd
# vi /etc/xinetd.d/rsync 將disable = yes 改爲 no


RSYNC_USER=admin
RSYNC_IP=10.10.10.20
PWD_PATH=/etc/rsync_client.pwd
RSYNC_MODULE=jin_static
NAS_PATH=/var/abver
# 需要排除的文件和目錄
# INOTIFY_EXCLUDE='(.*/*\.log|.*/*\.swp)$|^/tmp/src/mail/(2014|20.*/.*che.*)'
# inotifywait: --exclude ${INOTIFY_EXCLUDE}

# 需要排除的文件和目錄以列表形式保存在文件中,一條一行
# RSYNC_EXCLUDE='/etc/rsyncd.d/rsync_exclude.lst'
# rsync: --exclude-from=${RSYNC_EXCLUDE}



inotifywait -mrq --timefmt '%Y/%m/%d-%H:%M:%S:%s' --format '%T %w %f'  -e modify,delete,create,move,attrib ${NAS_PATH} | \
        while read file
        do
            # 將本地目錄同步到遠程主機上
            rsync -auvrtzopgP --delete --progress --password-file=${PWD_PATH} ${NAS_PATH} ${RSYNC_USER}@${RSYNC_IP}::${RSYNC_MODULE}
            # 從服務器上下載文件
            # rsync -auvrtzopgP --delete --password-file=/etc/rsyncd.secrets ${RSYNC_USER}@${RSYNC_IP}::${RSYNC_MODULE} /var/www/static
        done

發佈了61 篇原創文章 · 獲贊 26 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章