rsync+inotify 配置即時同步伺服器

來源:互聯網
上載者:User

1.安裝inofity-tools工具及rsync在伺服器上(注意是伺服器,即被備份的系統上),安裝rsync在用戶端上(即備份系統上,儲存伺服器的備份檔案)

2.在用戶端上配置:/etc/rsyncd.conf檔案,內容如下:

uid = nobodygid = nobodyuse chroot = nomax connections = 10strict modes = yespid file = /var/run/rsyncd.pidlock file = /var/run/rsync.locklog file = /var/log/rsyncd.log[yang11]
#這個目錄一定要存在path = /home/linux/savecomment = linux home dataignore errorsread only = nowrite only = nohosts allow = *hosts deny = 172.16.16.11list = falseuid = rootgid = rootauth users = backupsecrets file = /etc/server.pass

再在用戶端建立:/etc/server.pass檔案,且許可權為:600,內容如下:

backup:yang123

然後在用戶端啟動:rsync --daemon

3.在被備份的系統上寫個指令碼(即安裝了inofity-tools工具及rsync工具的系統上),假設名為:rsync_inotify.sh,內容如下:

#! /bin/bashhost1=172.16.16.202src=/home/linux/LinuxToolsuser="backup"modelName="yang11"/usr/bin/inotifywait -mrq --timefmt '%y/%m/%d %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src \| while read filesdo/usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/rsync.pass $src $user@$host1::$modelNameecho "$files was rsynced" >> /tmp/rsync.log 2>&1done

4.然後運行這個指令碼就可以了。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.