Backing up from your Ubuntu server to Amazon S3 Simple Storage Service

Sign up for an AWS account:
I use the free usage tier as I don’t need more than 5GB.
*** Note *** you need to provide a credit card number even for the free usage tier.
Login to the AWS interface and create a unique bucket.
For this demo I’ll call the bucket I’ve created ‘mybucket’.
Make a note of you Access Key ID and your Secret Key ID.
Access Key ID – 20-CHARACTER-CODE
Secret Key – 40-Character-Secret-Code

Install and Configure S3 Tools:
On your server download and configure S3Tools s3cmd from here http://s3tools.org/repositories#note-deb
Then import the S3tools signing key:

$ wget -O- -q http://s3tools.org/repo/deb-all/stable/s3tools.key | sudo apt-key add –
Add the repo to sources.list:
$ sudo wget -O/etc/apt/sources.list.d/s3tools.list http://s3tools.org/repo/deb-all/stable/s3tools.list
Refresh the package cache and install the newest s3cmd.
$ sudo apt-get update && sudo apt-get install s3cmd
Configuring s3cmd.

$ s3cmd –configure
New settings:
Access Key: 20-CHARACTER-CODE
Secret Key: 40-Character-Secret-Code
Encryption password: apassword
Path to GPG program: /usr/bin/gpg
Use HTTPS protocol: False
HTTP Proxy server name:
HTTP Proxy server port: 0
Configuration saved to ‘/home/username/.s3cfg’

Using s3cmd:
To copy a local file to the S3 ‘mybucket’ bucket
$ s3cmd put /home/username/myfolder/myfile.jpg s3://mybucket
Top copy a folder (need to use –recursive handle)
$ s3cmd put -r myfolder s3://oarbkup

Creating a script to perform the backup to AWS S3:
$ nano myscript
## put some nice text here ##
## I delete the previous backup on AWS S3 first ##

s3cmd del -r s3://mybucket/myfolder/
## Then Copy the folder and contents up to S3 ##

s3cmd put -r /home/username/myfolder/ s3://mybucket/myfolder/

## Then send an e-mail confirming the filecopy to S3 ##

echo “backup to AWS S3 completed” | mail -s “S3 backup status” –append=FROM:m<a href=”mailto:yserver me@mydomain.com

Add scripts to crontab scheduler:
$ crontab -e
append this to the file
# monday scripted backup to Amazon S3
10 22 * * 1 /home/username/myscript


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: