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