1、环境

服务器名称 IP地址 备注
backup-24-109 172.16.24.109
backup-24-108 172.16.24.108 目标

2、源主机Rsync安装

# dnf -y install rsync
# vi /etc/rsync_exclude.lst
test
test.txt

3、目标主机Rsync安装

# dnf -y install rsync rsync-daemon
# vim /etc/rsyncd.conf
...
pid file = /var/run/rsyncd.pid
log file = /var/log/rsyncd.log
max connections = 4
transfer logging = yes

[backup]
path = /data/backup
hosts allow = 172.16.24.109
hosts deny = *
list = true
uid = root
gid = root
read only = false
...

# 启动服务
systemctl enable --now rsyncd

4、在源主机上验证

mkdir /data/backup/{demo,db} -p
rsync -avz --delete --exclude-from=/etc/rsync_exclude.lst /data/backup/ 172.16.24.108::backup

5、在源主机上安装Lsync

# 安装
# dnf --enablerepo=epel -y install lsyncd

# 配置
# cat /etc/lsyncd.conf
...
-- sync{default.rsyncssh, source="/var/www/html", host="localhost", targetdir="/tmp/htmlcopy/"}

settings{
    statusFile = "/var/run/lsyncd.pid",
    statusInterval = 1,
}

sync{
    default.rsync,
    source="/data/backup/",
    target="172.16.24.108::backup",
    excludeFrom="/etc/rsync_exclude.lst",
}
...

# 启动服务
# systemctl enable --now lsyncd

参考:

https://github.com/lsyncd/lsyncd

  

posted on 2023-03-22 15:01  a120608yby  阅读(121)  评论(0编辑  收藏  举报