云计算和大数据 2019-11-03
之前写了一篇关于从CentOS备份到Windows的文章:inotify+rsync将服务器CentOS文件定时增量备份到Windows,现在改为备份到CentOS
IP地址 | 系统 | 功能 |
---|---|---|
192.168.1.100 | CentOS7.x | rsync服务端 |
192.168.1.101 | CentOS7.x | rsync客户端 |
yum install -y rsync
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
echo "myuser:mypassword" > /etc/rsyncd.secrets chmod +x /etc/rsyncd.secrets
systemctl restart rsyncd
yum install rsync -y
mypassword
chmod 600 /etc/rsync.passwd
inotify-tools工具监测文件增加、删除和修改,同时同步到备份服务器windows
yum install inotify-tools -y
#!/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
# 测试命令 /usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/rsync.passwd /root/test [email protected]::web1
inotify_start.sh &