Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a daily back up of my ec2 instance? [closed]

I have a community AMI based Linux EC2 instance in AWS. Now I want to take a daily back up of my instance, and upload that image in to S3.

Is that the correct way of doing the back up of my EC2 instance? Can anybody help me to point out the correct method for taking back up of my EC2 instance?

like image 343
hacker Avatar asked Jul 04 '12 05:07

hacker


People also ask

How do I schedule a backup for an EC2 instance?

Go to the EC2 instances, select the instance you want to schedule backup, and click on the Actions button. Select the instance settings>Manage tags from the dropdown list. Enter key and value and click on the Save button to add the tag.

Does EC2 provide automatic backup?

In this tutorial, you learn how to create an on demand backup job of an Amazon EC2 instance. Then, you will use a backup plan to protect EC2 resources. Using a backup plan within AWS Backup lets you automate backups using tags. Log in to the AWS Management Console, and open the AWS Backup console.

What is the easiest and safest way to backup in Amazon EC2?

First Method – EBS Snapshot One way of using EBS for backup is to create a snapshot of EBS volume used by EC2. EBS snapshot works as an external storage device. The user saves the instance at a given time and can restore it later (if the need arises).


1 Answers

Hopefully your instance is EBS backed.

If so, you can backup your instance by taking an EBS Snapshot. That can be done through aws.amazon.com (manually), using AWS Command Line Tools (which can be automated and scheduled in cron or Windows Task Scheduler as appropriate) or through the AWS API.

You want to ensure that no changes are made to the state of the database backup files during the snapshot process. When I used this strategy for MySQL running on Ubuntu, I used a script to ensure a consistent snapshot. That script uses a feature of the XFS file system to freeze the filesystem during the snapshot. In that deployment, the snapshot only took 2-3 seconds and was performed at a very off-peak time. Any website visitors would experience a 2-3 second lag. For Windows, if the device can not be rebooted for the snapshot (you have no maintenance window at night), I would instead create a separate EBS device (e.g. a "S:\" device for snapshots), use SQL Server backup tools to create a .bak file on that other device, then create an EBS snapshot of that separate EBS device.

For details on scripting the backup, see this related question:

Automating Amazon EBS snapshots anyone have a good script or solution for this on linux

If you have separate storage mounted e.g. for your database, be sure you back that up too!

UPDATE

To create a snapshot manually,

  • Browse to https://console.aws.amazon.com/ec2/home?#s=Volumes
  • Right-click on the volume you want to backup (the instance the volume is attached to is in the column named 'Attachment Information')
  • Select Create Snapshot

To create an AMI image from the instance and lauch other instances just like it (in instances with more resources or to balance load, etc.):

  • Browse to https://console.aws.amazon.com/ec2/home?#s=Instances
  • Right-click on the instance you want to create the AMI from
  • Select Create Image (EBS AMI)
like image 60
Eric J. Avatar answered Sep 28 '22 13:09

Eric J.