From a4a8b89cdd4617e0b584590350a0d5115dcd8ccc Mon Sep 17 00:00:00 2001 From: suecharo Date: Thu, 22 Aug 2024 16:40:40 +0900 Subject: [PATCH] Fix create bucket bug --- src/backup.sh | 9 +++++++-- src/public/backup.sh | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/backup.sh b/src/backup.sh index 3cdafc2..ff4df66 100644 --- a/src/backup.sh +++ b/src/backup.sh @@ -135,8 +135,13 @@ function do_backup() { local create_bucket=$(echo $S3_CONFIG | jq -r '.createBucket') if [[ $create_bucket == "true" ]]; then - log "Create bucket: $bucket_name" - aws s3api create-bucket --bucket $bucket_name --endpoint-url $endpoint_url + local exists=$(aws s3api head-bucket --bucket $bucket_name --endpoint-url $endpoint_url 2>&1 || true) + if [[ $exists == "" ]]; then + log "Bucket $bucket_name already exists, so skip create" + else + log "Create bucket: $bucket_name" + aws s3api create-bucket --bucket $bucket_name --endpoint-url $endpoint_url + fi fi local count=$(echo $BACKUP_FILES | jq -r ".${OPTION_POLICY} | length") diff --git a/src/public/backup.sh b/src/public/backup.sh index 3cdafc2..ff4df66 100644 --- a/src/public/backup.sh +++ b/src/public/backup.sh @@ -135,8 +135,13 @@ function do_backup() { local create_bucket=$(echo $S3_CONFIG | jq -r '.createBucket') if [[ $create_bucket == "true" ]]; then - log "Create bucket: $bucket_name" - aws s3api create-bucket --bucket $bucket_name --endpoint-url $endpoint_url + local exists=$(aws s3api head-bucket --bucket $bucket_name --endpoint-url $endpoint_url 2>&1 || true) + if [[ $exists == "" ]]; then + log "Bucket $bucket_name already exists, so skip create" + else + log "Create bucket: $bucket_name" + aws s3api create-bucket --bucket $bucket_name --endpoint-url $endpoint_url + fi fi local count=$(echo $BACKUP_FILES | jq -r ".${OPTION_POLICY} | length")