Ubuntu

使用 rsync 將文件從 Windows 傳輸到 Ubuntu

  • July 2, 2015

我在 Windows 上使用 rsync 和 cygwin 通過 ssh 將文件從 Windows 機器傳輸到 Ubuntu 機器時遇到問題。文件傳輸開始,但伺服器端新創建的目錄和文件總是在沒有使用者權限的情況下創建。因此,任何進一步寫入目錄或子目錄的嘗試都會從 rsync 返回眾多“Permission denied (13)”錯誤之一。我應該使用什麼正確的語法?我需要更明確的 rsyncd.conf 文件嗎?

在 Windows 端,我發出這個命令:

Patrick@ELWAH P:\Music
> rsync -avz --progress -h ./iTunes patrick@192.168.1.6:/mnt/largemarge

在伺服器端,它正在創建具有以下權限的目錄:

patrick@Ceres:/mnt/largemarge$ ll
total 12
drwxr-xr-x 3 patrick patrick 4096 Jul  1 22:16 ./
drwxr-xr-x 3 root    root    4096 Jul  1 20:23 ../
d---rwx--- 5 patrick patrick 4096 Jul  1 21:52 iTunes/
patrick@Ceres:/mnt/largemarge$

Windows 的輸出最終會產生錯誤,例如:

Patrick@ELWAH P:\Music
> rsync -avz --progress -h ./iTunes patrick@192.168.1.6:/mnt/largemarge
patrick@192.168.1.6's password:
sending incremental file list
rsync: recv_generator: mkdir "/mnt/largemarge/iTunes/Album Artwork/Cache" failed: Permission denied (13)
*** Skipping any contents from this failed directory ***
iTunes/Album Artwork/
iTunes/Album Artwork/Cache/
rsync: recv_generator: mkdir "/mnt/largemarge/iTunes/Album Artwork/Cloud Purchases" failed: Permission denied (13)
*** Skipping any contents from this failed directory ***
iTunes/Album Artwork/Cloud Purchases/
rsync: recv_generator: mkdir "/mnt/largemarge/iTunes/Album Artwork/Download" failed: Permission denied (13)
*** Skipping any contents from this failed directory ***
iTunes/Album Artwork/Download/
rsync: recv_generator: mkdir "/mnt/largemarge/iTunes/Album Artwork/Remote" failed: Permission denied (13)
*** Skipping any contents from this failed directory ***
rsync: recv_generator: mkdir "/mnt/largemarge/iTunes/Previous iTunes Libraries" failed: Permission denied (13)
*** Skipping any contents from this failed directory ***
rsync: recv_generator: mkdir "/mnt/largemarge/iTunes/iTunes Media" failed: Permission denied (13)
*** Skipping any contents from this failed directory ***
iTunes/Album Artwork/Remote/
iTunes/Previous iTunes Libraries/
iTunes/iTunes Media/

sent 2.10M bytes  received 13.33K bytes  103.31K bytes/sec
total size is 332.36G  speedup is 156,927.14
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1165) [sender=3.1.1]

rsync-a選項實際上是(根據手冊頁)的別名-rlptgoD。該-p列表中的“保留權限”;即,rsync 將對stat()源文件執行並將權限位複製到目標文件。

由於 windows 沒有任何 unix 權限,因此 cygwin 必須提出一個近似值,這必然受到一定的限制。如果您只是要求rsync複製權限,它將創建具有預設權限位的文件和目錄,並且問題不應該存在。

請注意,-gand-o分別代表“保留組”和“保留所有者”,出於類似原因,您可能也希望排除它們。

因此,您的整個命令變為:

rsync -rltvzD --progress -h <source> <destination>

引用自:https://unix.stackexchange.com/questions/213454