Skip to content

Commit

Permalink
Merge pull request #15 from Elium/master
Browse files Browse the repository at this point in the history
Add AWS_S3_BUCKET_CREATE option to create bucket if NoSuchBucket. resolves #23
  • Loading branch information
frekele authored Aug 4, 2016
2 parents 6086343 + ab54903 commit 0bdc215
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ENV STORAGE_PROVIDER='' \
CRON_SCHEDULE='' \
AWS_ACCESS_KEY_ID='' \
AWS_SECRET_ACCESS_KEY='' \
AWS_S3_BUCKET_CREATE='false' \
AWS_S3_BUCKET_NAME='' \
AWS_S3_PATH='/' \
AWS_DEFAULT_REGION='us-east-1' \
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
| AWS_ACCESS_KEY_ID | null | backup, restore | yes | tarball, sync | AWS access key. Eg: AKRJPMI3QYCARJCRF4VF |
| AWS_SECRET_ACCESS_KEY | null | backup, restore | yes | tarball, sync | AWS secret key. Eg: VCsrO7aVulGuiUdXbS31jtQA4iRTVgi4scftJAJr |
| AWS_S3_BUCKET_NAME | null | backup, restore | yes | tarball, sync | S3 bucket name. Eg: s3://my-bucket-backup/ |
| AWS_S3_BUCKET_CREATE | false | backup | no | tarball, sync | Boolean to indicate if we create the bucket (if not exists) |
| AWS_S3_PATH | / | backup, restore | no | tarball, sync | Relative path for bucket S3. Eg: (AWS_S3_BUCKET_NAME)/jenkins/ |
| AWS_DEFAULT_REGION | us-east-1 | backup, restore | no | tarball, sync | Default region bucket. Eg: (sa-east-1) |
| AWS_S3_OPTIONS | null | backup, restore | no | tarball, sync | AWS S3 options parameters. See in [AWS CLI S3] |
Expand Down Expand Up @@ -239,6 +240,14 @@ docker run --rm \
helicopterizer [backup|restore] --tarball
```

Run [Backup|Restore] with bucket creation (if NoSuchBucket):
```
docker run --rm \
........
-e AWS_S3_BUCKET_CREATE=true \
helicopterizer [backup|restore] --tarball
```

Run With clean the date before the restore:

***[Be careful here, you will lose all your data inside DATA_PATH directory].***
Expand Down
14 changes: 14 additions & 0 deletions scripts/core/helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ printEnvs(){
echo "AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID"
echo "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY"
echo "AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION"
echo "AWS_S3_BUCKET_CREATE=$AWS_S3_BUCKET_CREATE"
echo "AWS_S3_BUCKET_NAME=$AWS_S3_BUCKET_NAME"
echo "AWS_S3_PATH=$AWS_S3_PATH"
echo "AWS_S3_OPTIONS=$AWS_S3_OPTIONS"
Expand Down Expand Up @@ -189,3 +190,16 @@ mountUriS3(){
s3Uri="s3://$s3Uri"
echo "$s3Uri"
}

createS3Bucket(){
# Check if create is required
if [ "$AWS_S3_BUCKET_CREATE" = "true" ]; then
local bucketS3Uri="s3://$AWS_S3_BUCKET_NAME"
# Test if bucket doesn't exists
if aws s3 ls "s3://$AWS_S3_BUCKET_NAME" 2>&1 | grep -q 'NoSuchBucket'; then
# Create bucket
local s3BucketCreationResult=$(aws s3 mb "$bucketS3Uri")
echo "$s3BucketCreationResult"
fi
fi
}
4 changes: 3 additions & 1 deletion scripts/provider/aws/sync/upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ SyncUploadToS3(){
echo "$s3Result"
}


uploadSync(){
#Call to mount uri S3.
s3Uri=$(mountUriS3 "/" $AWS_S3_BUCKET_NAME $AWS_S3_PATH)

local createS3BucketResult=$(createS3Bucket)
echo "$createS3BucketResult"

echo "Starting Upload Sync from: $DATA_PATH/ to $s3Uri/"
local s3Result=$(SyncUploadToS3)
echo "$s3Result"
Expand Down
3 changes: 3 additions & 0 deletions scripts/provider/aws/tarball/upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ uploadTarball(){
#Call to mount uri S3.
s3Uri=$(mountUriS3 $1 $AWS_S3_BUCKET_NAME $AWS_S3_PATH)

local createS3BucketResult=$(createS3Bucket)
echo "$createS3BucketResult"

echo "Starting Upload Tarball from: /tmp/$1 to $s3Uri"
local s3Result=$(uploadToS3 $1)
echo "$s3Result"
Expand Down

0 comments on commit 0bdc215

Please sign in to comment.