AWS S3 Backup Guide 2, aws-cli

If you already have aws-cli installed and want to send a file to Amazon S3 it’s really easy:

aws s3 cp ARCHIVE_TO_SEND s3://BUCKET_NAME/ARCHIVE_TO_SEND

 

Sending files ‘by hand’ is all good, but if you are serious about backups you need to automate the process, here is a quick and dirty backup script.
It lists, tars, bzips and individually uploads all the directories under the path you specify o the script.
 
You just need to set the variables at lines 5, 6, 7 and 8.
Continue reading “AWS S3 Backup Guide 2, aws-cli”

AWS S3 Backup guide 1, bash script

If you don’t have ( or don’t want ) aws-cli installed you can upload files under 5gb with the following script:

#!/bin/bash
# Size limit of 5gb, if you need to upload a bigger file use AWS Cli tools
# $1 Must be the full path of the file
file=$(basename $1)

# S3 authentication information
bucket="<NameOfTheAwsBucket>"
s3Key=""<AWSAccessUser>"
s3Secret="<AWSAccessKey>"
awspath=s3.amazonaws.com
resource="/${bucket}/${file}"

# as we are uploading a backup the need to be a tar archive
contentType="application/x-compressed-tar"
dateValue=$(date -R)
stringToSign="PUT\n\n${contentType}\n${dateValue}\n${resource}"


# Signature magic :)
signature=$(echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64)

curl -X PUT -T "${file}" -H "Host: ${bucket}.s3.amazonaws.com" -H "Date: ${dateValue}" -H "Content-Type: ${contentType}" -H "Authorization: AWS ${s3Key}:${signature}" https://${bucket}.${awspath}/${file}

 
Continue reading “AWS S3 Backup guide 1, bash script”