以前寫了一篇關於從CentOS備份到Windows的文章:inotify+rsync將服務器CentOS文件定時增量備份到Windows,如今改成備份到CentOSphp
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 myuser@192.168.1.101::web1
inotify_start.sh &