Rsync实现主机间实时备份文件

51 篇文章 0 订阅
#!/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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值