歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux教程

rsync從linux到linux的文件同步備份

  一、環境
    需要備份文件的服務器(服務器端):192.168.1.201 (RHEL 5)
    接收備份文件的服務器(客戶端):192.168.1.202 (CENTOS 5)

    二、安裝配置
     1.服務器端的配置
        A、采用系統默認安裝的rsync 編輯/etc/rsyncd.conf文件,如果沒有則新建一個。
       vi /etc/rsyncd.conf
    #[globale]
    strict modes= yes  #check passwd file
    port= 873 #default port
    logfile= /var/log/rsyncd.log
    pidfile= /var/run/rsyncd.pid
    max connections= 4
    #[modules]
    [testlink]   #備份模塊
    uid= root
    gid= root
    path= /usr/local/apache/htdocs/testlink/upload_area  #要備份的目錄
    read only= no
    host allow= *
    auth users= wwyhy
    secrets file= /etc/rsyncd.scrt
    [bugfree]         #備份模塊
    uid= root
    gid= root
    path= /usr/local/apache/htdocs/bugfree/BugFile         #要備份的目錄
    read only= no
    host allow= *
    auth users= wwyhy
    secrets file= /etc/rsyncd.scrt
    [redmine]   #備份模塊
    uid= root
    gid= root
    path= /usr/local/redmine-0.8.1/files       #要備份的目錄
    read only= no
    host allow= *
    auth users= wwyhy
    secrets file= /etc/rsyncd.scrt

    B、 添加一個密碼文件
    vi /etc/rsyncd.scrt
    內容如下:
    wwyhy:123456  #(自己設置)

    C、改變權限為600
    chmod 600 /etc/rsyncd.scrt

    D、啟動服務(如開有防火牆請允許873端口通過)
    rsync --daemon --config=/etc/rsyncd.conf &

    2.配置客戶端
    客戶端我則自己編譯安裝的rsync-3.0.3.tar.gz的
    A、安裝:
    tar -zxvf rsync-3.0.3.tar.gz
    cd rsync-3.0.3
    ./configure
    make
    make install
    B、添加密碼文件
    vi /etc/rsyncd.scrt (沒有就新建)
    內容如下:
    wwyhy:123456 (文件與客戶端文件內容一樣)
    C、改文件權限為600
    chmod 600 /etc/rsyncd.scrt

    三、開始備份
    可以在客戶端通過man rsync指令來查看備份指令
    我們用腳本來自動執行備份
    列:rsync -avz --password-file=密碼文件路徑 username@需要備份的主機IP::備份裡的模塊名稱
     接收備份文件的路徑
    在/root建一個腳本文件
    vi backup

    添加內容如下:
    #1.192.168.1.201上的testlink附件備份指令
    rsync -avz --password-file=/etc/rsyncd.scrt [email protected]::testlink
    /home/wangwei/testlink/upload_area
    #2.192.168.1.201上的bugfree附件備份指令
    rsync -avz --password-file=/etc/rsyncd.scrt [email protected]::bugfree
    /home/wangwei/bugfree/BugFile
    #3.192.168.1.201上的redmine附件備份指令
    rsync -avz --password-file=/etc/rsyncd.scrt [email protected]::redmine
    /home/wangwei/redmine-0.8.1/files

    chmod u+x backup

    每晚2.30自動執行
    vi /etc/crontab

    30 2 * * * root /root/backup

Copyright © Linux教程網 All Rights Reserved