Created
August 29, 2016 17:11
-
-
Save ferdhie/e8f8beb3cec0013abd309575267ea21d to your computer and use it in GitHub Desktop.
Backup file to s3
This file contains 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 | |
file="file-to-backup.gz" | |
contentType="application/x-gzip" | |
bucket="bucketname" | |
region="ap-southeast-1" | |
resource="/${bucket}/${file}" | |
dateValue=`date -R` | |
stringToSign="PUT\n\n${contentType}\n${dateValue}\n${resource}" | |
s3Key="XXXXXXXXXXXXXXXXX" | |
s3Secret="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | |
signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64` | |
echo "$stringToSign | $signature" | |
curl -i -X PUT -T "${file}" \ | |
-H "Host: ${bucket}.s3.amazonaws.com" \ | |
-H "Date: ${dateValue}" \ | |
-H "Content-Type: ${contentType}" \ | |
-H "Authorization: AWS ${s3Key}:${signature}" \ | |
https://${bucket}.s3-${region}.amazonaws.com/${file} | |
rm -rf $file | |
cd $pwd | |
echo "Backup done\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment