如何从aws s3 sync命令中排除该文件夹

时间:2018-02-12 18:33:24

标签: bash shell amazon-web-services aws-cli jenkins-cli

我们有一个aws s3 sync命令,可以通过Jenkins执行shell将数据从bitbucket同步到s3。 下面是s3桶结构

cdn-accountname > qa > sitename > cdn > img
cdn-accountname > qa > sitename > cdn > css
cdn-accountname > qa > sitename > cdn > png

我们使用以下命令将cdn内容从bitbucket同步到s3

aws s3 sync cdn/ s3://cdn-accountname/qa/sitename

我想在cdn /文件夹中排除“/ upload”和“/ upload_qa”文件夹并将其同步到s3。我试过下面的命令,但没有一个工作

aws s3 sync --exclude "cdn/upload" --exclude "cdn/upload_qa" cdn/ s3://cdn-accountname/qa/sitename
aws s3 sync --exclude=cdn/upload --exclude=cdn/upload_qa cdn/ s3://cdn-accountname/qa/sitename
aws s3 sync --exclude "*/upload/*" --exclude "*/upload_qa/*" cdn/ s3://cdn-accountname/qa/sitename
aws s3 sync --exclude 'upload/*' --exclude 'upload_qa/*' cdn/ s3://cdn-accountname/qa/sitename 
aws s3 sync cdn/ s3://cdn-accountname/qa/sitename --exclude 'upload/*' --exclude 'upload_qa/*'
aws s3 sync cdn/ s3://cdn-accountname/qa/sitename --exclude "cdn/upload" --exclude "cdn/upload_qa"
aws s3 sync cdn/ s3://cdn-accountname/qa/sitename --exclude=cdn/upload --exclude=cdn/upload_qa
aws s3 sync cdn/ s3://cdn-accountname/qa/sitename --exclude "*/upload/*" --exclude "*/upload_qa/*" 

建议使用可行的s3 sync命令来同步不包含子文件夹的文件夹

1 个答案:

答案 0 :(得分:0)

我相信您还需要在命令中使用--include标记(请参阅docs以供参考)

aws s3 sync --include "*" --exclude "upload/*" --exclude "upload_qa/*" cdn/ s3://cdn-accountname/qa/sitename

小心订单

  

如果有多个过滤器,则规则是显示的过滤器   稍后在命令中优先于先前出现的过滤器   在命令中

经过测试,工作正常

home [~]: aws s3 ls s3://abc-fe-testing1
                           PRE folder1/
                           PRE folder2/
                           PRE folder3/
                           PRE folder4/
home [~]: aws s3 ls s3://abc-fe-testing2
home [~]: aws s3 sync s3://abc-fe-testing1 s3://abc-fe-testing2 --exclude "folder1*" --exclude "folder2*"
copy: s3://abc-fe-testing1/folder4/file_from_folder4.txt to s3://abc-fe-testing2/folder4/file_from_folder4.txt
copy: s3://abc-fe-testing1/folder3/file_from_folder3.txt to s3://abc-fe-testing2/folder3/file_from_folder3.txt
home [~]: aws s3 ls s3://abc-fe-testing2
                           PRE folder3/
                           PRE folder4/