How to backup EC2 instance

Hi, I have an EC2 instance (Bitnami Ubuntu ) running on AWS. I would like to backup the whole instance. what should I do? thanks
tonitoni99Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Zephyr ICTCloud ArchitectCommented:
First check if you have an EBS backed volume, if you have, you can take snapshots of your instance.

Now snapshots are like incremental backups so you can take as many or as little as you want and keep your backups fresh, you can also use these snapshots to create an image, so you could always start another instance from that image (or extra instances).

These snapshots can be taken manually via the aws console or automated using  the AWS Command Line Tools or through the AWS API. Using the AWS Command Line Tools you can automate the snapshot process using chron or the Windows equivalent, so that snapshots (backups) are taken automatically. You could also backup the snapshots to an S3 volume on Amazon for example.

Also, if you have extra volumes, containing databases for example, don't forget to include snapshots for those as well...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Shalom CarmelCTOCommented:
This is a script I am using for a server to backup itself. The script uses the EC2 CLI and the instance metadata, and is run weekly via crond.
It runs on the Amazon Linux, so you may have to adjust the tools locations.


#!/bin/sh

export AWS_ACCESS_KEY=your-access-key
export AWS_SECRET_KEY=your-secret-key


export PATH=$PATH:/opt/aws/bin
export JAVA_HOME=/usr/lib/jvm/jre
export EC2_HOME=/opt/aws/apitools/ec2

DATE=`date +%Y-%m-%d`
TIME=`date +'%R:%S'`

# REGION  eu-west-1       ec2.eu-west-1.amazonaws.com
# REGION  sa-east-1       ec2.sa-east-1.amazonaws.com
# REGION  us-east-1       ec2.us-east-1.amazonaws.com
# REGION  ap-northeast-1  ec2.ap-northeast-1.amazonaws.com
# REGION  us-west-2       ec2.us-west-2.amazonaws.com
# REGION  us-west-1       ec2.us-west-1.amazonaws.com
# REGION  ap-southeast-1  ec2.ap-southeast-1.amazonaws.com
# REGION  ap-southeast-2  ec2.ap-southeast-2.amazonaws.com

# find availability zone, for example eu-west-1b
EC2_AVAILABILITY_ZONE=`curl http://169.254.169.254/latest/meta-data/placement/availability-zone`

# remove last letter to get region
EC2_REGION="${EC2_AVAILABILITY_ZONE%?}"
# set EC2_URL environment variable. We ignore it by using the --region switch directly
# export EC2_URL=ec2.$EC2_REGION.amazonaws.com

# find this instance id
EC2_INSTANCE_ID=`curl http://169.254.169.254/latest/meta-data/instance-id/`

# find this volume. only works for single volume servers.
ec2string=`ec2-describe-instance-attribute  --region $EC2_REGION  $EC2_INSTANCE_ID -b`
ec2arr=($ec2string)
EC2_VOLUME=${ec2arr[2]}

# send backup and get snapshot id
echo ec2-create-snapshot  --region $EC2_REGION  $EC2_VOLUME -d "Weekly backup $DATE.$TIME"

ec2string=`ec2-create-snapshot  --region $EC2_REGION  $EC2_VOLUME -d "Weekly backup $DATE.$TIME"`
ec2arr=($ec2string)
EC2_SNAPSHOT=${ec2arr[1]}


# get Name attribute
echo ec2-describe-tags --region $EC2_REGION --filter "resource-id=$EC2_INSTANCE_ID" --filter "key=Name"

ec2string=`ec2-describe-tags --region $EC2_REGION --filter resource-id=$EC2_INSTANCE_ID --filter key=Name`
ec2arr=($ec2string)
EC2_INSTANCE_NAME=${ec2arr[4]}

# create Name tag for snapshot
echo ec2-create-tags  --region $EC2_REGION  $EC2_SNAPSHOT --tag "Name=$EC2_INSTANCE_NAME"
ec2-create-tags  --region $EC2_REGION  $EC2_SNAPSHOT --tag "Name=$EC2_INSTANCE_NAME"

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
AWS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.