本文以兩台主機為例:Rsync 伺服器為 192.168.0.160,Rsync 客戶端為 192.168.0.159,說明如何完成遠端同步與自動備份。
先編譯安裝 rsync,接著透過 xinetd 以服務模式啟動。重點是 server_args 要指向自訂的 rsyncd.conf,讓服務載入正確設定。
在安裝目錄下建立 etc、man、var 等子目錄,並撰寫 rsyncd.conf。設定內容通常包含 log file、pid file、lock file、secrets file、read only、hosts allow、hosts deny、uid、gid、max connections 等。
模組部分可定義 mailstore、maildb、maildatabase,各自指定 path、comment 與 auth users,方便不同備份點分開管理。
secrets 檔格式為使用者:密碼。完成後必須將 rsyncd.conf 與 rsyncd.secrets 權限設為 600,否則客戶端可能出現 auth failed,伺服器日誌也會提示 secrets file 權限過於開放。
客戶端安裝相同版本後,可撰寫 shell 腳本,透過 RSYNC_PASSWORD 環境變數自動向多個模組同步。腳本常用參數包括 force、ignore-errors、pogt、delete、backup、backup-dir 與 az,可做到壓縮傳輸與增量備份。
實務上建議將備份日誌固定寫入檔案,並依日期建立 old 目錄,方便後續回溯與還原。