目录
环境:
用途: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