inotify+rsync将服务器CentOS文件定时增量备份到另外CentOS
背景
之前写了一篇关于从CentOS备份到Windows的文章:inotify+rsync将服务器CentOS文件定时增量备份到Windows,现在改为备份到CentOS
服务器配置
IP地址 | 系统 | 功能 |
---|---|---|
192.168.1.100 | CentOS7.x | rsync服务端 |
192.168.1.101 | CentOS7.x | rsync客户端 |
rsync服务端
1. 安装rsync
yum install -y rsync
2. 配置/etc/rsyncd.conf
transfer logging = yes log file = /var/log/rsyncd.log pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock uid = nobody gid = nobody use chroot = no ignore errors read only = no [web1] path = /root/test auth users = myuser secrets file = /etc/rsyncd.secrets host allow = * hosts deny = * list = false
3. 新建/etc/rsyncd.secrets
echo "myuser:mypassword" > /etc/rsyncd.secrets chmod +x /etc/rsyncd.secrets
4. 启动服务
systemctl restart rsyncd
rsync客户端
1. 安装rsync
yum install rsync -y
2. 新建/etc/rsync.passwd,内容如下,注意客户端rsync只需要密码
mypassword
3. 更改权限
chmod 600 /etc/rsync.passwd
4. 安装inotify
inotify-tools工具监测文件增加、删除和修改,同时同步到备份服务器windows
yum install inotify-tools -y
5. 启动脚本inotify_start.sh
#!/bin/bash host=192.168.1.101 src=/home/backup des=web1 user=myuser inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src | while read files do /usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/rsync.passwd $src $user@$host::$des echo "${files} was rsynced" >>/tmp/rsync.log 2>&1 done
6. 测试
# 测试命令 /usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/rsync.passwd /root/test [email protected]::web1
7. 后台运行启动脚本
inotify_start.sh &
相关推荐
Proudoffaith 2019-10-25
xiaoemo0 2020-06-17
awoyaoc 2020-06-12
wiseMale 2020-05-31
会哭的雨 2020-05-30
ITlover00 2020-05-26
plusz 2020-05-09
深井兮兮 2020-05-01
jiangtie 2020-04-30
净无邪 2020-04-26
Wytheme 2020-02-16
secondid 2020-02-03
秋风瑟瑟 2020-01-06
会哭的雨 2019-12-12
insularisland 2019-12-06
leodengzx 2019-12-03
博小瑾 2014-03-18
ourtimes 2015-05-02