简体   繁体   English

在此 AWS CLI 命令中,为什么使用 --exclude 和 --include 通配符复制文件不起作用?

[英]In this AWS CLI command, why copying files with --exclude & --include wildcards not working?

In the following directory, I want to upload only the .html files in top /DirA/ to the root of my AWS bucket:在以下目录中,我只想将顶部/DirA/.html文件上传到我的 AWS 存储桶的根目录:

/DirA/ , eg /DirA/ ,例如

.file
fileA.html
fileB.html
fileC.bin
/subdirA
/subdirB

When I run the this:当我运行这个:

me@me:/DirA$ aws s3 cp ./ s3://MYBUCKET/ --dryrun --exclude "*" --include "*.html"

The .html files are not handled by aws and I just get the empty prompt me@me:/DirA$ back. .html文件不是由 aws 处理的,我只是得到空提示me@me:/DirA$回来。 No error or the usual (dry run) upload: message.没有错误或通常的(dry run) upload:消息。

I have also tried我也试过

me@me:/$ aws s3 cp /DirA/ s3://MYBUCKET/ --dryrun --exclude "*" --include "*.html"

with the same empty prompt.具有相同的空提示。

Please note (if helpful):请注意(如果有帮助):

  1. The above were in Ubuntu 18.04 with latest installed AWS CLI v1.以上是在 Ubuntu 18.04 中最新安装的 AWS CLI v1。
  2. I also installed AWS CLI in Windows and did the same, with similar empty result.我还在 Windows 中安装了 AWS CLI 并执行了相同的操作,结果为空。
  3. Uploading stuff which does not require --exclude or --include like that works normally上传不需要--exclude--include东西正常工作

What am I doing wrong and how to fix that.我做错了什么以及如何解决这个问题。 Thank you very much.非常感谢。

I do believe you are missing the --recursive option on your command.我相信您在命令中缺少 --recursive 选项。

Inside your folder:在您的文件夹中:

aws s3 cp . aws s3 cp。 s3://DESTINATION_BUCKET/ --dryrun --exclude="*" --include="*.html" --recursive s3://DESTINATION_BUCKET/ --dryrun --exclude="*" --include="*.html" --recursive

I found nothing that sustains this need on the doc, although local tests show that only works with this parameter.我在文档上没有发现任何支持这种需求的东西,尽管本地测试表明它只适用于这个参数。

Here's the link for the doc on AWS: https://docs.aws.amazon.com/cli/latest/reference/s3/index.html#use-of-exclude-and-include-filters这是 AWS 上文档的链接: https : //docs.aws.amazon.com/cli/latest/reference/s3/index.html#use-of-exclude-and-include-filters

josedasilva is right, you need to use the --recursive flag. josedasilva是对的,您需要使用--recursive标志。 Now, to only include only the current directory files, you need to mix some include and exclude flags.现在,要仅包含当前目录文件,您需要混合使用一些包含和排除标志。

This should do the job:这应该可以完成这项工作:

aws s3 cp --recursive ./ s3://MYBUCKET/ --exclude "*" --include "*.html" --exclude "*/*"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM