rsync Server多客户端备份数据

目录

环境:

rsync Server端

rsync Client端

同步脚本

任务计划

 

inotify 脚本


环境:

用途:rsync Server端    主机名:influxdb-1-8-3-45-bak    IP:10.3.0.45    软件:rsync

用途:rsync Client端     主机名:influxdb-1-8-3-15           IP:10.3.0.15    软件:rsync


rsync Server端

yum -y install rsync

注意:

配置文件中的【uid=0、gid=0】表示使用root用户去同步,这样可以解决 “没有权限”的问题【rsync failed: Permission denied (13)】

vim /etc/rsyncd.conf

 

# /etc/rsyncd: configuration file for rsync daemon mode

# See rsyncd.conf man page for more options.

# configuration example:

# uid = nobody
# gid = nobody
uid = 0
gid = 0
use chroot = yes
address = 10.3.0.45
port = 873
hosts allow = 10.3.0.0/24
read only = no
# max connections = 4
# pid file = /var/run/rsyncd.pid
# exclude = lost+found/
# transfer logging = yes
# timeout = 900
# ignore nonreadable = yes
# dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2

# [ftp]
#        path = /home/ftp
#        comment = ftp export area

[bak]
    path = /var/lib/influxdb/
    dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
    auth users = backuper
    secrets file = /etc/rsyncd_users.db

 

vim /etc/rsyncd_users.db
backuper:abc123
chmod 600 /etc/rsyncd_users.db

 

systemctl enable rsyncd.service
systemctl restart rsyncd.service

rsync Client端

yum -y install rsync
vim /etc/rsyncd-server.pass
abc123
chmod 600 /etc/rsyncd-server.pass

同步脚本

# 准备一个专门放脚本的目录
mkdir /script

vim /script/influxdb-rsync-bak-45.sh
#!/bin/bash
# author: sunsh
# date: 2021-04-16
# qq: 2471783741

# 因为备份的数据里,是没有删除操作的,为了避免人为的误删除,所以同步的命令中不使用“--delete”参数

# rsync -avH --progress --delete --password-file=/etc/rsyncd-server.pass /var/lib/influxdb/ backuper@10.3.0.45::bak
rsync -avH --progress --password-file=/etc/rsyncd-server.pass /var/lib/influxdb/ backuper@10.3.0.45::bak

任务计划

crontab -e
*/5     *       *       *       *       sh /script/influxdb-rsync-bak-45.sh  # add sunsh
systemctl enable crond.service
systemctl restart crond.service

 

 

 

inotify

注意:

inotify并不适合 多级目录、多文件、数据量大”的同步。

# 准备一个专门放脚本的目录
mkdir /script

vim /script/inotify.sh
#!/bin/bash
# author: sunsh
# date: 2021-04-15
# qq: 2471783741
# 
INOTIFY_CMD="inotifywait -mrq -e modify,create,move,delete,attrib /var/lib/influxdb/"
RSYNC_CMD="rsync -avH --progress --delete --password-file=/etc/rsyncd-server.pass /var/lib/influxdb/ backuper@10.3.0.45::bak"

$INOTIFY_CMD | while read DIRECTORY EVENT FILE
do
        if  [ $(pgrep rsync | wc -l) -le 0 ] ; then
                $RSYNC_CMD
        fi
done

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值