无法使用 rsync 将目录从远程主机拉到本地

无法使用 rsync 将目录从远程主机拉到本地

我的问题只是我试图解决的一个更大问题的一小部分。

该问题始于rsync非常复杂且由 ansible 构建的命令,并且不起作用......在此报告:

https://stackoverflow.com/questions/73859216/ansible-synchronize-module-fails-to-get-directory-from-remote-to-local-failed

我希望从一个简单的 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

请建议。

答案1

根据rsync --help

--recursive, -r 递归到目录

所以当你想复制一个目录时,你必须添加-r--recursive选项rysnc:

/bin/rsync -rv myremoteuser@myremotehost:/tmp/Deployments/ /web/playbooks/automation/getfiles/tmpfiles/4/E5EA787E/myremotehost/

答案2

使用rsync -a而不是普通的rsync.

如果没有-a( --archive) 标志,您既不会递归复制,也不会获取文件元数据。至少需要使用( mtime) 复制的文件修改时间 ( )才能有选择地跳过它认为已复制的文件。如果确定文件的大小和上次修改时间在源和目标上相同,则它倾向于避免执行校验和,但显然如果没有将文件修改时间复制到目标,这些将不匹配并且无法优化其传输算法。-t--timesrsyncrsyncrsync

相关内容