Created
March 4, 2020 17:55
-
-
Save marcorivm/cebd839fa85880d0997daf66ab85ae01 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # You don't need some other library to upload to S3 -- shell works perfectly fine | |
| # Based on a modified script from here https://gist.github.com/chrismdp/6c6b6c825b07f680e710 and here http://tmont.com/blargh/2014/1/uploading-to-s3-in-bash | |
| S3KEY="YOURKEY" | |
| S3SECRET="YOURSECRET" | |
| S3BUCKET="YOURBUCKET" | |
| S3STORAGETYPE="ONEZONE_IA" #REDUCED_REDUNDANCY or STANDARD etc. | |
| AWSREGION="s3" | |
| function putS3 | |
| { | |
| path=$1 | |
| file=$2 | |
| aws_path=$3 | |
| bucket="${S3BUCKET}" | |
| date=$(date +"%a, %d %b %Y %T %z") | |
| acl="x-amz-acl:private" | |
| content_type="application/octet-stream" | |
| storage_type="x-amz-storage-class:${S3STORAGETYPE}" | |
| string="PUT\n\n$content_type\n$date\n$acl\n$storage_type\n/$bucket$aws_path" | |
| signature=$(echo -en "${string}" | openssl sha1 -hmac "${S3SECRET}" -binary | base64) | |
| curl -s -X PUT -T "$path/$file" \ | |
| -H "Host: $bucket.${AWSREGION}.amazonaws.com" \ | |
| -H "Date: $date" \ | |
| -H "Content-Type: $content_type" \ | |
| -H "$storage_type" \ | |
| -H "$acl" \ | |
| -H "Authorization: AWS ${S3KEY}:$signature" \ | |
| "https://$bucket.${AWSREGION}.amazonaws.com$aws_path" | |
| } | |
| date=$(date +"%a_%d_%b_%Y__%H_%M_%S") | |
| mysqldump -h 127.0.0.1 -uforge -p<DB_PWD> --single-transaction --routines --triggers <DB_NAME> > backup_"${date}".sql | |
| putS3 . backup_"${date}".sql "/${date}.sql" | |
| rm *.sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment