公司如今有一個需求,須要將服務器CentOS的文件定時增量到Windows服務器,Windows服務器鏈接了存儲服務器磁盤陣列,空間比較大。基於這樣的需求,咱們採用inotify+rsync增量備份的解決方案。php
IP地址 | 系統 |
---|---|
192.168.1.100 | CentOS7.x |
192.168.1.101 | Windows Server 2012 r2 |
注意:這裏的服務器名和密碼用於後面配置項目中,默認用戶名:SvcCWRSYNC,密碼設置爲admin123
use chroot = false strict modes = false hosts allow = * log file = rsyncd.log uid = 0 # 須要配置此項,否則鏈接報錯 gid = 0 # 須要配置此項,否則鏈接報錯 # Module definitions # Remember cygwin naming conventions : c:\work becomes /cygwin/c/work # #[test] #path = /cygdrive/c/work #read only = false #transfer logging = yes [rsyncdata] path = /cygdrive/e/cdbid-pro1.0-backup/57 read only = false # 只讀屬性爲false list = no hosts allow = * auth users = SvcCWRSYNC # 對應配置用戶名 secrets file = /cygdrive/e/cdbid-pro1.0-backup/rsync.passwd
SvcCWRSYNC:admin123
yum install rsync -y
admin123
chmod 600 /etc/rsync.passwd
inotify-tools工具監測文件增長、刪除和修改,同時同步到備份服務器windows
yum install inotify-tools -y
#!/bin/bash host=192.168.1.101 src=/home des=rsyncdata user=SvcCWRSYNC 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 SvcCWRSYNC@192.168.1.101::rsyncdata
inotify_start.sh &
轉載請註明:溜爸 » inotify+rsync將服務器CentOS文件定時增量備份到Windowswindows