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

1

51

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?

Fioritura answered 4/7, 2012 at 5:41 Comment(0)
V
46

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,

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.):

Vaclava answered 4/7, 2012 at 5:46 Comment(9)
yes my instance is ebs backed.can u pls tell me how to take an ebs snapshot in aws console?Fioritura
Updated my answer accordingly.Vaclava
i have one sqlitedb within that instance,if i do like this that also will be backed up?Fioritura
If your sqlitedb is stored on the same volume as the operating system, yes. (In other words, if you have not mounted extra EBS volumes, it will be backed up too). I suggest launching a new instance from the backup (by right-clicking on the backup) and making sure that everything runs as expected in that new instance. You can then kill the new instance (be sure you don't kill the "real" one :-)Vaclava
have to consult you in lot of occasions so that i am a newbee in this area.can u give me any other contacting option like gtalk?Fioritura
This doesn't sound like a good idea because making a backup of a 30 gigabyte server can take a few minutes, and during this time certain non-atomic events can happen - for example SQL access. This can introduce problems into your CMS and will be almost impossible to get out. You should write your own dedicated backup, such as a script to dump sql and copy the data - anything else is lazy and dangerous.Ermina
What if it's instance storage, what methods exist for that?Beech
When I backed up joomla I was making an sql backup a dump as Mikhail said and also the site files - which get added to with things like images etc... I don't know but the console based backups I imagine incur a cost ?Chitin
What kind of cost? Performance? Financial? When you backup an entire EBS device, the block copy is performed in the storage device itself. The performance cost to your app should be minimal. However, if the data on the EBS device is changing (e.g. a database), it is very wise to allow the backup to reboot the instance to avoid inconsistencies in the file system. When backing up a DB, I would do a normal DB backup (with DB tools) to a separate EBS device, then backup that device. If you mean financial cost, you pay a small fee per GB for snapshots.Vaclava

© 2022 - 2024 — McMap. All rights reserved.