Linux
無法使用 rsync 將目錄從遠端主機拉到本地
我的問題只是我試圖解決的一個更大問題的一小部分。
該問題始於
rsync
非常複雜且由 ansible 建構且不起作用的命令……此處報告:我希望從一個簡單的 rsync 命令開始,將文件夾從遠端主機複製到本地。
它複製的是遠端是一個文件,但如果遠端是一個目錄則失敗。
$ /bin/rsync --version rsync version 3.1.2 protocol version 31 Copyright (C) 1996-2015 by Andrew Tridgell, Wayne Davison, and others. Web site: http://rsync.samba.org/ Capabilities: 64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints, socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace, append, ACLs, xattrs, iconv, symtimes, prealloc rsync comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See the GNU General Public Licence for details. [mylocaluser@mylocalhost myremotehost]$ uname -a Linux mylocalhost 3.10.0-1160.76.1.el7.x86_64 #1 SMP Tue Jul 26 14:15:37 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Rsync 為文件工作:
$ /bin/rsync -v myremoteuser@myremotehost:/tmp/Deployments/pay.war /web/playbooks/automation/getfiles/tmpfiles/4/E5EA787E/myremotehost/ This system is for the use by authorized users only. All data contained on all systems is owned by the company and may be monitored, intercepted, recorded, read, copied, or captured in any manner and disclosed in any manner, by authorized company personnel. Users (authorized or unauthorized) have no explicit or implicit expectation of privacy. Unauthorized or improper use of this system may result in administrative, disciplinary action, civil and criminal penalties. Use of this system by any user, authorized or unauthorized, constitutes express consent to this monitoring, interception, recording, reading, copying, or capturing and disclosure. IF YOU DO NOT CONSENT, LOG OFF NOW. ################################################################## # *** This Server is using Centrify *** # # *** Remember to use your Active Directory account *** # # *** password when logging in *** # ################################################################## pay.war sent 43 bytes received 83 bytes 252.00 bytes/sec total size is 0 speedup is 0.00
但是,當我提供目錄而不是文件時,它不起作用。
$ /bin/rsync -v myremoteuser@myremotehost:/tmp/Deployments/ /web/playbooks/automation/getfiles/tmpfiles/4/E5EA787E/myremotehost/ This system is for the use by authorized users only. All data contained on all systems is owned by the company and may be monitored, intercepted, recorded, read, copied, or captured in any manner and disclosed in any manner, by authorized company personnel. Users (authorized or unauthorized) have no explicit or implicit expectation of privacy. Unauthorized or improper use of this system may result in administrative, disciplinary action, civil and criminal penalties. Use of this system by any user, authorized or unauthorized, constitutes express consent to this monitoring, interception, recording, reading, copying, or capturing and disclosure. IF YOU DO NOT CONSENT, LOG OFF NOW. ################################################################## # *** This Server is using Centrify *** # # *** Remember to use your Active Directory account *** # # *** password when logging in *** # ################################################################## skipping directory . sent 8 bytes received 30 bytes 25.33 bytes/sec total size is 0 speedup is 0.00
請建議。
根據
rsync --help
:–recursive, -r 遞歸到目錄
因此,當您要複製目錄時,您必須添加
-r
or--recursive
選項rysnc:
/bin/rsync -rv myremoteuser@myremotehost:/tmp/Deployments/ /web/playbooks/automation/getfiles/tmpfiles/4/E5EA787E/myremotehost/
使用
rsync -a
代替普通的rsync
.如果沒有
-a
(--archive
) 標誌,您既不會遞歸複製,也不會獲得文件元數據。至少,需要使用 ( ) 複製的文件修改時間 ( )mtime
才能-t
有選擇地跳過它認為已複製的文件。如果確定文件的大小和最後修改時間在源和目標上相同,則它更願意避免執行校驗和,但顯然如果沒有將文件修改時間複製到目標,這些將不匹配並且無法優化其傳輸算法。--times``rsync``rsync``rsync