大网数据广告活动
服务器运维问答

rsync remote find prefixes home directory?

· 52CE 我爱测

I am attempting to pull everything from a remote directory which is more then ten minutes old, and then remove the source files. My remote find seems to be working (tested independently on the remote box), but when rsync goes to …

问题原文

原帖链接 · Spot · CC BY-SA 4.0

I am attempting to pull everything from a remote directory which is more then ten minutes old, and then remove the source files.

My remote find seems to be working (tested independently on the remote box), but when rsync goes to use it, my user's home path is being prefixed to the find output, like so:

rsync -avz --dry-run --remove-source-files --files-from=<(ssh spot@host "find /mnt/volume_2/partners/test/uploads/ -amin +10 -type f,d -print0") spot@host:. .

receiving incremental file list
rsync: [sender] link_stat "/home/spot/mnt/volume_2/partners/test/uploads" failed: No such file or directory (2)
rsync: [sender] link_stat "/home/spot/mnt/volume_2/partners/test/uploads/file-1054" failed: No such file or directory (2)
rsync: [sender] link_stat "/home/spot/mnt/volume_2/partners/test/uploads/file-1105" failed: No such file or directory (2)
rsync: [sender] link_stat "/home/spot/mnt/volume_2/partners/test/uploads/file-1105/subfile-1105" failed: No such file or directory (2)
rsync: [sender] link_stat "/home/spot/mnt/volume_2/partners/test/uploads/file-1101" failed: No such file or directory (2)
rsync: [sender] link_stat "/home/spot/mnt/volume_2/partners/test/uploads/file-1056" failed: No such file or directory (2)
rsync: [sender] link_stat "/home/spot/mnt/volume_2/partners/test/uploads/file-1058" failed: No such file or directory (2)

I've spent more time than I'd like to admit attempting to resolve this with no success. I am hoping someone here is nice enough to point me in the right direction.

Thank you!

已采纳解答

原帖链接 · anx · CC BY-SA 4.0

rsync is looking at the wrong place, because those paths are relative (from the rsync man page, emphasis mine):

--files-from=FILE

[..]

The filenames that are read from the FILE are all relative to the source dir

Either send absolute paths to the files-from option, but do not additionally define a source directory other than the root (/). This should work - I replaced one character after the host name:

rsync -avz --dry-run --remove-source-files --from0 --files-from=<(ssh spot@host "find /mnt/volume_2/partners/test/uploads/ -amin +10 -type f,d -print0") spot@host:/ .

Or - and especially useful when you actually want to deal with relative paths in the destination - tell find to emit relative paths and actually use them:

ssh spot@host "cd /mnt/volume_2/partners/test/uploads/; find -amin +10 -type f,d -print0" | rsync -avz --dry-run --remove-source-files --from0 --files-from=- spot@host:/mnt/volume_sfo2_01/partners/test/uploads/ .

Note I switched the <() redirection to a normal | pipe for better interoperability and less surprises while escaping the command for inclusion in scripts. I also added --from0 on top of your comment because the input is now null-delimited so it makes sense to tell rsync it is so.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-11-06)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。