# 詳解 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 
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kawsing.gitbook.io/opensystem/andoid-shou-ji/untitled/rsync-server/xiang-jie-rsync-server.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
