rsync 實現本地時時檔案同步,rsync實現同步

來源:互聯網
上載者:User

rsync 實現本地時時檔案同步,rsync實現同步

即時同步:
實現即時同步(也就是來源目錄中的內容發生變化,他就會觸發同步,實現兩邊的目錄內容完全相同)

inotify+rsync

軟體名稱:
inotify-tools-3.13.tar.gz(自行網站下載)

解壓安裝該源碼包的步驟:

# tar xzvf inotify-tools-3.13.tar.gz -C /usr/src/
# cd /usr/src/inotify-tools-3.13/
# ./configure
# make
# make install

--安裝完後,就會產生下面兩個命令
/usr/local/bin/inotifywait
/usr/local/bin/inotifywatch

  

測試本機/test/目錄裡一有(增,刪,改,屬性改變),就會同步到/test2/目錄

 

mkdir手動建立/test 和/test2目錄

然後使用下面的指令碼來實現同步:


#vim /tmp/1.sh

  #!/bin/bash


  /usr/local/bin/inotifywait -mrq -e modify,delete,create,attrib,move /test|while read files

  do
  rsync -a --delete /test/ /test2/
  done

修改指令碼許可權:
 #chmod 0755 /tmp/1.sh
輸入以下命令,執行上面寫的指令碼!
# nohup sh /tmp/1.sh & 

游標會停止並閃爍再敲擊一次斷行符號,會在/test/目錄 下產生nohup.out檔案  :

  

 

 

再然後對/test/目錄進行各種操作,驗證可以即時同步到/test2/目錄

驗證同步成功。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.