> For the complete documentation index, see [llms.txt](https://kawsing.gitbook.io/opensystem/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kawsing.gitbook.io/opensystem/andoid-shou-ji/untitled/rsync-server/xiang-jie-rsync-server.md).

# 詳解 rsync server

在常駐模式（daemon mode）下，rsync server 預設監聽TCP埠873

Rsync在備份時，主要是傳送**資料差異**的部份，因此大多都被使用在**差異備份**上。除了資料第一次傳輸是整份檔案外，之後都只會傳送資料間異動的部份。

### 設定上，有兩個重要檔案:

```
/etc/rsyncd.conf #為rsync設定檔 
/etc/rsyncd.secrets #為rsync 密碼檔
```

### &#x20;伺服器端設定

```
nano /etc/rsyncd.conf
#模組名稱 
 [Rsync]                                   
           #說明
           comment = backup test
           #允許使用rsync連入的ip
           hosts allow = 172.16.10.9  
           #不允許連入的ip，*表示全檔
           hosts deny = *                
           #存放備份資料的目錄
           path = /srv/dev-disk-by-label-data/Rsync       
           #認證帳號 (要設定於rsyncd.secrets 內的帳號)
           auth users = root   
           #用來啟動rsync server 的uid
           uid = root                    
           #用來啟動rsync server 的gid 
           gid = root                    
           #密碼檔存放路徑
           secrets file = /etc/rsyncd.secrets      
           #是否設定為唯讀
           read only = no        
           #不要對這些附檔名的檔案做壓縮
           dont compress = *.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2 *.tbz
                                          
```

```
nano /etc/rsyncd.secrets
#設定格式=> 帳號:密碼
root:password  
#必須修改rsyncd.secrets使用權限 (很重要)
chmod 600 /etc/rsyncd.secrets
chown root.root  /etc/rsyncd.secrets
```

### service rsync restart

測試看看是否都正常 (rsync的port為873)

```
netstat -tnlp | grep 873
tcp    0    0 0.0.0.0:873        0.0.0.0:*         LISTEN      4235/xinetd

telnet localhost 873  
#若出現下列訊息表示正常
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
@RSYNCD: 29
```

### Client端設定

在Client主機上只需要設定密碼就可以。

```
nano /etc/rsyncd.secrets
#設定格式:  密碼
password
#修改rsyncd.secrets使用權限 (很重要)
chmod 600 /etc/rsyncd.secrets
chown root.root  /etc/rsyncd.secrets
```

### 測試Client端rsync是否可傳輸資料

```
rsync -avrHS --delete --password-file=/etc/rsyncd.secrets  /opt/* root@172.16.10.12::Rsync 
```
