linux中用rsync同步備份檔案配置方法

來源:互聯網
上載者:User

linux rsync同步設定

rsync是一款資料鏡像備份工具,可以保持兩個伺服器間資料同步,用得最多的情境就是備份資料了。
安裝方法如下:

安裝

在UBUNTU下安裝RSYNC通過以下步驟可以實現:

 代碼如下 複製代碼
$ sudo apt-get install rsync xinetd

配置
1. 編輯/etc/default/rsync 啟動rsync作為使用xinetd的守護進程

 代碼如下 複製代碼
$ sudo vim /etc/default/rsync
  RSYNC_ENABLE=inetd

2. 建立 /etc/xinetd.d/rsync 通過xinetd使rsync開始工作

 代碼如下 複製代碼


$ sudo vim /etc/xinetd.d/rsync
  service rsync
    {
        disable         = no
        socket_type     = stream
        wait            = no
        user            = root
        server          = /usr/bin/rsync
        server_args     = --daemon
        log_on_failure  += USERID
    }

3. 建立 /etc/rsyncd.conf  配置rsync使其在.

 代碼如下 複製代碼

$ sudo vim /etc/rsyncd.conf
  max connections = 2
  log file = /var/log/rsync.log
  timeout = 300

  [share]
  comment = Public Share
  path = /home/share
  read only = no
  list = yes
  uid = nobody
  gid = nogroup
  auth users = user
  secrets file = /etc/rsyncd.secrets

4. 建立 /etc/rsyncd.secrets  配置使用者名稱和密碼.

 代碼如下 複製代碼

$ sudo vim /etc/rsyncd.secrets
  user:password

4.a

 代碼如下 複製代碼

$ sudo chmod 600 /etc/rsyncd.secrets

5. 啟動/重啟 xinetd

 代碼如下 複製代碼

$ sudo /etc/init.d/xinetd restart

測試


運行下面的命令檢查,確認rsync配置成功。

 代碼如下 複製代碼

$ sudo rsync user@192.168.0.1::share
  Password:
  drwxr-xr-x        4096 2006/12/13 09:41:59 .
  drwxr-xr-x        4096 2006/11/23 18:00:03 folders


如果沒成功,幾點注意一下:

 代碼如下 複製代碼

/etc/rsyncd.conf:
auth users = user

後面的user是被授權可以訪問這個module的使用者,需要與/etc/rsyncd.secrets裡對應。
遠程同步:

 代碼如下 複製代碼

sudo rsync -arlHptgzqh --delete --delay-updates --progress fhp@serverip::share --password-file=/etc/rsync_password /media/Server/server1/home

/etc/rsync_password

只需要填密碼就可以了


遺憾的是rsync同步工作並不能自動檢測目錄是否有檔案更新或更改然後自動同步,而需要我們在系統的計劃任務中進行同步操作。

相關文章

聯繫我們

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