#!/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
Rsync实现主机间实时备份文件
最新推荐文章于 2024-04-25 09:41:44 发布