简体   繁体   English

从 S3 文件夹下载文件并为其创建文件夹的 Shell 脚本

[英]Shell Script that downloads files from S3 folder and also creates folders for them

I wrote a shell script that uses awscli to get files from a few folders in s3.我编写了一个 shell 脚本,它使用 awscli 从 s3 中的几个文件夹中获取文件。 The issues I am having is that when I run the script, it create the folders, but the files are just downloaded in one.我遇到的问题是,当我运行脚本时,它会创建文件夹,但文件只是下载为一个。 the folders that are created are named the same as in S3.创建的文件夹的名称与 S3 中的名称相同。 How can I modify this script so that the folders are created, but the files are downloaded into their corresponding folder.如何修改此脚本以创建文件夹,但将文件下载到相应的文件夹中。

#!/bin/bash -e


DIRNAME='s3download'
SLASH='/'
SEVENFOLDERS=( "folder1" "folder2" "folder3" "folder4" "folder5" "folder6" "folder7" )
SEVENFOLDERPATH=("s3://blah/folder1/" 
"s3://blah/folder2/" "s3://blah/folder3/" "s3://blah/folder4/" "s3://blah/folder5/" "s3://blah/folder6/" "s3://blah/folder7/" )

mkdir $DIRNAME
for i in "${SEVENFOLDERS[@]}"
do
:
SUBDIR=$DIRNAME$SLASH$i
mkdir -p $SUBDIR
done

for k in "${SEVENFOLDERPATH[@]}"
do
:
SUBDIR=$DIRNAME$SLASH$k
aws s3 cp --recursive $k $SUBDIR
done
echo $i "Status: 200 OK"
fi

aws s3 sync将下载与 S3 结构相同的文件。

以下命令替换日期节点中的值。

sed -i -e '/<System>/,/<\/System>/ s|<Date>[0-9a-z:/ .]\{1,\}</Date>|<Date>'"$newDate"'</Date>|g' sample.xml 

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

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