rsync
rsync 是一個很方便的檔案同步工具,可以在本機或是網路上同步檔案。因為它可只針對有異動的檔案進行同步,速度相當快,因此有很多人都拿來當作備份工具。

安裝rsync
CentOS 預設已先將 rsync 裝好,使用yum安裝也很容易:

yum install rsync



相關設定檔

/etc/rsyncd.conf
備份伺服器設定檔,這個檔案用來設定哪些主機可以將檔案用rsync同步過來,檔案內容如下:

[client1]                        #主機代號,可自訂
path = /rsyser                #設定目錄
auth users = xiang           #使用者帳號,可自訂
uid = root                      #執行時的uid
gid = root                      #執行時的gid
secrets file = /etc/rsyncd.secrets    #密碼檔的路徑
read only = no                #是否唯讀


/etc/rsyncd.secrets

密碼檔

內容很簡單:
username:password

username就是rsyncd.conf裡設定的auth users
password就是這個帳號的密碼拉,這要跟client對的起來


指令

rsync
選項
r   遞迴複製,可針對目錄來執行rsync
v  顯示更多資訊
l   複製連結檔屬性
p  複製時屬性會與原始檔相同
o  複製時擁有人會與原始檔相同
g  複製時擁有群組會與原始檔相同
D  複製時裝置屬性會與原始檔相同
t  複製時時間參數與原始檔相同
a  代表使用 rlptgoD 這些選項

長選項
--password-file=/root/rsyncd.secrets
後面接的是密碼設定檔的路徑

指令範例
rsync -rvlpogDt --password-file=/root/rsyncd.secrets  /rsyclient xiang@192.168.1.15::client1
/rsyclient  代表要備份的目錄
xiang@192.168.1.15::client1  備份伺服器參數:
xiang 代表username
@  後面接備份伺服器位址
client1 代表備份伺服器設定裡的備份主機代號


建置實做

server端
1. 打開 rsync 服務


[root@test etc]# vi  /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
}


2. 開啟 xinetd
[root@test etc]# service xinetd start

3. 建立 /etc/rsyncd.conf

[root@test etc]# vi /etc/rsyncd.conf
[client1]
path = /rsyser
auth users = xiang
uid = root
gid = root
secrets file = /etc/rsyncd.secrets
read only = no

4. 建立 /etc/rsyncd.secrets
[root@test etc]# vi /etc/rsyncd.secrets
username:password

5. 變更權限與owner
chown root.root rsyncd.secrets
chmod 600 rsyncd.secrets


client端
1. 建立密碼檔,此檔案只要紀錄密碼即可

[root@localhost ~]# vi rsyncd.secrets

2. 變更權限與owner
chown root.root rsyncd.secrets
chmod 600 rsyncd.secrets

3. 執行 rsync
[root@localhost ~]# rsync -rvlpogDt --password-file=/root/rsyncd.secrets  /rsyclient xiang@192.168.1.15::client1

building file list ... done
rsyclient/
rsyclient/01.MP3
rsyclient/02.MP3
rsyclient/03.MP3
rsyclient/04.MP3
rsyclient/05.MP3
rsyclient/06.MP3
rsyclient/07.MP3
rsyclient/08.MP3
rsyclient/09.MP3
rsyclient/10.MP3
rsyclient/11.MP3
rsyclient/12.MP3
rsyclient/13.MP3
rsyclient/14.MP3
rsyclient/15.MP3


sent 99301127 bytes  received 440 bytes  5092388.05 bytes/sec
total size is 99287527  speedup is 1.00
You have new mail in /var/spool/mail/root


完成....


參考資料:
http://www.backup.idv.tw/good_doc/linux/backup/20030726/rsync.htm
http://phorum.study-area.org/index.php/topic,15553.html
http://www.openfoundry.org/tw/tech-article/2184


arrow
arrow
    全站熱搜

    xiangyang17 發表在 痞客邦 留言(0) 人氣()