一:linux 系統默認含有rsync的安裝包,直接yum安裝即可:
yum install rsync -y
#[globale]
strict modes = yes #強制密碼驗證
port = 873 #配置默認端口,也可以不寫
logfile = /var/log/rsyncd.log
pidfile = /var/run/rsyncd.pid
max connections =10
#[modules]
[module_A] #備份模塊A
uid = root
gid = root
path = /backup_path #要備份的目錄
read only = no
host allow = IP 指定IP信任,* 表示沒有限制
auth users = test
secrets file= /etc/rsyncd.scrt #指定密碼文件位置
[module_B] # 參考A的配置,依次類推即可
*****
*****
添加一個密碼文件
vi /etc/rsyncd.scrt
內容如下:
test:123456 #爲test賬戶指定密碼
改變權限爲600
chmod 600 /etc/rsyncd.scrt #600權限意在防止密碼文件被獲取
啓動服務(如開有防火牆請允許873端口通過)
rsync --daemon --config=/etc/rsyncd.conf &
客戶端配置:
首先創建密碼文件:
vi /etc/rsyncd.scrt 添加內容爲:
test:123456
改文件權限爲600
chmod 600 /etc/rsyncd.scrt
同步命令:
rsync -avz --password-file=/etc/rsyncd.scrt test@主server_IP::module_A
rsync常用參數參考
-v,--verbose 詳細模式輸出;
-a,--archive 歸檔模式,表示以遞歸的方式傳輸文件,並保持所有文件屬性不變,相當於使用了組合參數-rlptgoD;
-r, --recursive 對子目錄以遞歸模式處理;
-l, --links 保留軟鏈結;
-p, --perms 保持文件權限;
-t, --times 保持文件時間信息;
-g, --group 保持文件屬組信息;
-o, --owner 保持文件屬主信息;
-D, --devices 保持設備文件信息;
-H, --hard-links 保留硬鏈結;
-S, --sparse 對稀疏文件進行特殊處理以節省DST的 空間;
--delete 刪除那些DST中SRC沒有的文件;
-z, --compress 對備份的文件在傳輸時進行壓縮處理