Backup files in EC2 Instance to Amazon S3

EC2 Instance : Ubuntu Server 12.04 LTS
Tool : s3cmd

Install s3cmd:

sudo apt-get install s3cmd

Configure s3cmd for managing data on S3:
Get the access key, secret key from your AWS account prior to this step.

s3cmd --configure

Listing buckets:

s3cmd ls

Create a bucket:

s3cmd mb s3://bucket_name

Upload files to S3:

s3cmd put -r ~/backup_directory/ s3://bucket_name/

Synchronize files:

s3cmd sync -r ~/backup_directory/ s3://bucket_name/

Download files from a bucket:

s3cmd get -r s3://bucket_name/ ~/my_s3_downloads/

Delete files in a bucket:

s3cmd del -r s3://bucket_name/

Remove a bucket:

s3cmd rb -f s3://bucket_name

Write a shell script to synchronize files in the EC2 Instance:
backup_sync_ec2_s3.sh

#!/bin/bash
s3cmd sync -r ~/backup_directory/ s3://bucket_name/

Edit crontab file:

crontab -e

Schedule script:
Add cronjob to trigger automated backup everyday at 23:59 hrs

59 23 * * * sh ~/backup_sync_ec2_s3.sh 
Advertisements

One thought on “Backup files in EC2 Instance to Amazon S3

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