通过外壳脚本执行时,AWS S3 Sync忽略--exclude参数

时间:2019-04-15 17:13:02

标签: shell aws-cli

我正在尝试创建一个外壳程序脚本(Mac OSX),该脚本使用命名的参数并基于这些参数执行AWS S3 Sync命令。我在S3中有几个文件夹带有“ config.xml”文件。我想做的是仅通过向Shell脚本提供文件夹名称,上载/下载和dryrun选项来下载或上传这些文件之一。

问题是执行脚本时,--exclude“ *”被忽略,但是如果我回显该命令,然后将输出复制并粘贴到Terminal中,则它将正常工作。

我看到了一些有关设置noglob的帖子,但它似乎不适用于我的情况,但是我还是尝试了一下,但未能解决问题。

#!/bin/bash
dryrun=true
dryarg=""
while getopts rs:c: option
do
    case "${option}"
    in
        s ) sync=${OPTARG};;
        c ) client=${OPTARG};;
        r ) dryrun=false;;
        \? ) echo "$(tput setaf 1)Unknown option: -$OPTARG$(tput sgr 0)" >&2; exit 1;;
        :  ) echo "$(tput setaf 1)Missing option argument for -$OPTARG$(tput sgr 0)" >&2; exit 1;;
        *  ) echo "$(tput setaf 1)Unimplemented option: -$OPTARG$(tput sgr 0)" >&2; exit 1;;
    esac
done
if [ ! "$sync" ] || [ ! "$client" ]
then
    echo "$(tput setaf 1)sync method and client are required options"
    echo "nothing is happening until you declare these!!$(tput sgr 0)"
    exit 1
fi
if [ "$dryrun" == "true" ]
then
    dryarg="--dryrun"
else 
    dryarg=""
fi
if [ "$sync" == "u" ] || [ "$sync" == "upload" ]
then
    echo "$(tput setaf 2)uploading $dryarg $(tput sgr 0)"
    echo $(tput setaf 2)aws s3 sync . s3://mybucket --exclude '"*"' --include '"'"$client"'/config.xml"' "$dryarg"$(tput sgr 0)
    aws s3 sync s3://etl.elevatemaps.io .  --exclude '"*"' --include '"'"$client"'/config.xml"' "$dryarg"
elif [ "$sync" == "d" ] || [ "$sync" == "download" ]
then
    echo "$(tput setaf 3)downloading $dryarg $(tput sgr 0)"
    echo $(tput setaf 3)aws s3 sync s3://mybucket . --exclude '"*"' --include '"'"$client"'/config.xml"' "$dryarg"$(tput sgr 0)
    aws s3 sync s3://etl.elevatemaps.io . --exclude '"*"' --include '"'"$client"'/config.xml"' "$dryarg"
fi
fi

如果我执行

./sync.sh -s download -c FolderA
uploading --dryrun 
aws s3 sync s3://mybucket . --exclude "*" --include "FolderA/config.xml" --dryrun

,但是S3输出显示每个正在下载的文件夹,dryrun很受好评。如果我复制并粘贴命令,它将正确执行。 如果我执行

./sync.sh -s upload  -c FolderA
uploading --dryrun 
aws s3 sync . s3://mybucket --exclude "*" --include "FolderA/config.xml" --dryrun

aws cli出现错误,指示参数不正确。

有人可以帮我解决这个问题吗?

0 个答案:

没有答案