scp,文件结构保存不一致
scp, inconsistency for file structure preservation
- 我的任务:从多个服务器收集日志文件。
- 服务器文件结构:“/remote/path/dir/sub-dirs/files.log”,其中
在所有服务器上都是一样的。 (所有服务器都有相同的一组
"sub-dirs",可能会缺席,当然还有 "files.log" 个名字
不同)
- 本地文件结构:“/local/path/logs”
- 复制后我想要
“/local/path/logs/目录/子目录/files.log”
- 方法(在服务器的 whlile 循环中):scp -r
$服务器:/remote/path/dir /local/path/logs
- 问题:由于我不明白的原因,第一个scp命令
忽略 "dir" 文件夹,我得到“/local/path/logs/sub-dirs/files.log”
但是遵循 scp 命令给了我我想要的
“/local/path/logs/目录/子目录/files.log”
- 为什么会发生这种情况,我应该如何fix/get解决这个问题?
谢谢!
Why is this happening [...]
在命令中scp -r path/to/source dest
:
- 如果
dest
不存在,将创建dest
目录,并将path/to/source/*
复制到其中。例如,如果您有 path/to/source/X
,那么将创建 dest/X
。
- 如果
dest
是一个目录,那么dest/source
将被创建,path/to/source/*
将被复制到其中。例如,如果您有 path/to/source/X
,那么将创建 dest/source/X
。
[...] and how should I fix/get around it?
提前创建dest
,例如:
mkdir -p /local/path/logs
scp -r $SERVERS:/remote/path/dir /local/path/logs
- 我的任务:从多个服务器收集日志文件。
- 服务器文件结构:“/remote/path/dir/sub-dirs/files.log”,其中 在所有服务器上都是一样的。 (所有服务器都有相同的一组 "sub-dirs",可能会缺席,当然还有 "files.log" 个名字 不同)
- 本地文件结构:“/local/path/logs”
- 复制后我想要 “/local/path/logs/目录/子目录/files.log”
- 方法(在服务器的 whlile 循环中):scp -r $服务器:/remote/path/dir /local/path/logs
- 问题:由于我不明白的原因,第一个scp命令 忽略 "dir" 文件夹,我得到“/local/path/logs/sub-dirs/files.log” 但是遵循 scp 命令给了我我想要的 “/local/path/logs/目录/子目录/files.log”
- 为什么会发生这种情况,我应该如何fix/get解决这个问题?
谢谢!
Why is this happening [...]
在命令中scp -r path/to/source dest
:
- 如果
dest
不存在,将创建dest
目录,并将path/to/source/*
复制到其中。例如,如果您有path/to/source/X
,那么将创建dest/X
。 - 如果
dest
是一个目录,那么dest/source
将被创建,path/to/source/*
将被复制到其中。例如,如果您有path/to/source/X
,那么将创建dest/source/X
。
[...] and how should I fix/get around it?
提前创建dest
,例如:
mkdir -p /local/path/logs
scp -r $SERVERS:/remote/path/dir /local/path/logs