問題背景:在配置好rsync服務和客戶端后,客戶端從服務端拉取是正常的,但從客戶端推送到服務端報錯。
a,單獨推送目錄會報這個錯誤
rsync: recv_generator: mkdir "opt" (in backup) failed: Permission denied (13)
[root@nfs01:/opt]# rsync -avz /opt rsync_backup@10.0.0.41::backup
Password:
sending incremental file list
rsync: recv_generator: mkdir "opt" (in backup) failed: Permission denied (13)
*** Skipping any contents from this failed directory ***
opt/
sent 472 bytes received 172 bytes 257.60 bytes/sec
total size is 697,812 speedup is 1,083.56
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1178) [sender=3.1.2]
如果從客戶端向服務端推送目錄和文件也報錯rsync: chgrp ".backup.sh.RwFAWn" (in backup) failed: Operation not permitted (1)。但文件傳過去了,目錄並沒有傳過去
[root@nfs01:/opt]# rsync -avz /opt/ rsync_backup@10.0.0.41::backup
Password:
sending incremental file list
./
backup.sh
hejian.txt
services
rsync: chgrp ".backup.sh.RwFAWn" (in backup) failed: Operation not permitted (1)
rsync: chgrp ".hejian.txt.iLqEOb" (in backup) failed: Operation not permitted (1)
rsync: chgrp ".services.vxwJGZ" (in backup) failed: Operation not permitted (1)
sent 136,811 bytes received 340 bytes 21,100.15 bytes/sec
total size is 697,812 speedup is 5.09
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1178) [sender=3.1.2]
然后檢查/backup目錄的權限被修改成了550,原來設置的是755,然后把權限修改成755后再重新操作
[root@backup:/backup]# ls -ld /backup/
dr-xr-x--- 3 rsync rsync 312 Sep 1 07:54 /backup/
root@backup:/backup]# chmod 755 /backup/
[root@backup:/backup]# ls -ld /backup/
drwxr-xr-x 4 rsync rsync 324 Sep 1 08:03 /backup/
但修改完后再通過客戶端同步,還是報上面的錯,並且剛修改的目錄權限又變成了550
從網上查詢的說是selinux影響,但我檢查兩台服務器的selinux設置的都是disabled,防火牆也處於關閉狀態
[root@backup:/backup]# getenforce
Disabled
經排查是由於-a參數導致的,因為-a是歸檔模式傳輸,並保持所有文件屬性,等價於-rtopgDl(還沒有具體深入研究),可以使用下面這個命令替代
[root@nfs01:/opt]# rsync -rltDvz /opt/ rsync_backup@10.0.0.41::backup
如果還想使用-avz這個參數組合的話,可以在rsyncd.conf配置文件中添加一個參數fake super = yes也能解決問題
,同樣的命令和配置文件rsync在CentOS6系統之前是不需要的,CentOS7系統需要增加這個參數才不會報錯