使用 AWS S3 同步排除多个文件夹
Exclude multiple folders using AWS S3 sync
如何在使用 aws s3 syn 时排除多个文件夹?
我试过了:
# aws s3 sync s3://inksedge-app-file-storage-bucket-prod-env \
s3://inksedge-app-file-storage-bucket-test-env \
--exclude 'reportTemplate/* orders/* customers/*'
但它仍在为文件夹“customer”进行同步
输出:
copy: s3://inksedge-app-file-storage-bucket-prod-env/customers/116/miniimages/IMG_4800.jpg
to s3://inksedge-app-file-storage-bucket-test-env/customers/116/miniimages/IMG_4800.jpg
copy: s3://inksedge-app-file-storage-bucket-prod-env/customers/116/miniimages/DSC_0358.JPG
to s3://inksedge-app-file-storage-bucket-test-env/customers/116/miniimages/DSC_0358.JPG
最后这对我有用:
aws s3 sync s3://my-bucket s3://my-other-bucket \
--exclude 'customers/*' \
--exclude 'orders/*' \
--exclude 'reportTemplate/*'
提示:您必须将通配符和特殊字符用单引号或双引号括起来才能正常工作。以下是匹配字符的示例。有关 S3 命令的更多信息,请查看 amazon here.
*: Matches everything
?: Matches any single character
[sequence]: Matches any character in sequence
[!sequence]: Matches any character not in sequence
对于那些正在寻找同步存储桶中某些子文件夹的人,排除过滤器适用于正在同步的文件夹内的文件和文件夹,而不是相对于存储桶的路径,例如:
aws s3 sync s3://bucket1/bootstrap/ s3://bucket2/bootstrap --exclude '*' --include 'css/*'
会同步以下文件夹树中的文件夹 bootstrap/css 但不会 bootstrap/js 和 bootstrap/fonts:
bootstrap/
├── css/
│ ├── bootstrap.css
│ ├── bootstrap.min.css
│ ├── bootstrap-theme.css
│ └── bootstrap-theme.min.css
├── js/
│ ├── bootstrap.js
│ └── bootstrap.min.js
└── fonts/
├── glyphicons-halflings-regular.eot
├── glyphicons-halflings-regular.svg
├── glyphicons-halflings-regular.ttf
└── glyphicons-halflings-regular.woff
也就是说,过滤器是 'css/*' 而不是 'bootstrap/css/*'
https://docs.aws.amazon.com/cli/latest/reference/s3/index.html#use-of-exclude-and-include-filters
中的更多内容
在 Windows 命令提示符下,只有双引号有效,因此在通配符周围使用“”,例如:
aws s3 sync s3://bucket-1/ . --exclude "reportTemplate/*" --exclude "orders/*"
单引号在 Windows 10.
上不起作用(使用 --dryrun 选项测试)
当我们有多层文件夹结构时,我使用了一些不同的方式。将 '**' 与 --include
一起使用
命令:
aws s3 sync s3://$SOURCE_BUCKET/dir1/dir2/ s3://$TARGET_BUCKET/dir1/dir2/ --include "**/**'
如何在使用 aws s3 syn 时排除多个文件夹?
我试过了:
# aws s3 sync s3://inksedge-app-file-storage-bucket-prod-env \
s3://inksedge-app-file-storage-bucket-test-env \
--exclude 'reportTemplate/* orders/* customers/*'
但它仍在为文件夹“customer”进行同步
输出:
copy: s3://inksedge-app-file-storage-bucket-prod-env/customers/116/miniimages/IMG_4800.jpg
to s3://inksedge-app-file-storage-bucket-test-env/customers/116/miniimages/IMG_4800.jpg
copy: s3://inksedge-app-file-storage-bucket-prod-env/customers/116/miniimages/DSC_0358.JPG
to s3://inksedge-app-file-storage-bucket-test-env/customers/116/miniimages/DSC_0358.JPG
最后这对我有用:
aws s3 sync s3://my-bucket s3://my-other-bucket \
--exclude 'customers/*' \
--exclude 'orders/*' \
--exclude 'reportTemplate/*'
提示:您必须将通配符和特殊字符用单引号或双引号括起来才能正常工作。以下是匹配字符的示例。有关 S3 命令的更多信息,请查看 amazon here.
*: Matches everything
?: Matches any single character
[sequence]: Matches any character in sequence
[!sequence]: Matches any character not in sequence
对于那些正在寻找同步存储桶中某些子文件夹的人,排除过滤器适用于正在同步的文件夹内的文件和文件夹,而不是相对于存储桶的路径,例如:
aws s3 sync s3://bucket1/bootstrap/ s3://bucket2/bootstrap --exclude '*' --include 'css/*'
会同步以下文件夹树中的文件夹 bootstrap/css 但不会 bootstrap/js 和 bootstrap/fonts:
bootstrap/
├── css/
│ ├── bootstrap.css
│ ├── bootstrap.min.css
│ ├── bootstrap-theme.css
│ └── bootstrap-theme.min.css
├── js/
│ ├── bootstrap.js
│ └── bootstrap.min.js
└── fonts/
├── glyphicons-halflings-regular.eot
├── glyphicons-halflings-regular.svg
├── glyphicons-halflings-regular.ttf
└── glyphicons-halflings-regular.woff
也就是说,过滤器是 'css/*' 而不是 'bootstrap/css/*'
https://docs.aws.amazon.com/cli/latest/reference/s3/index.html#use-of-exclude-and-include-filters
中的更多内容在 Windows 命令提示符下,只有双引号有效,因此在通配符周围使用“”,例如:
aws s3 sync s3://bucket-1/ . --exclude "reportTemplate/*" --exclude "orders/*"
单引号在 Windows 10.
上不起作用(使用 --dryrun 选项测试)当我们有多层文件夹结构时,我使用了一些不同的方式。将 '**' 与 --include
一起使用命令:
aws s3 sync s3://$SOURCE_BUCKET/dir1/dir2/ s3://$TARGET_BUCKET/dir1/dir2/ --include "**/**'