Reputation: 1715
I have an EBS backed EC2 running instance. The EBS store holds a database. I would like to create an AMI from this. Can someone please provide guidelines?
Thanks for your patience through a long question. I recognize there's similar information out there, but nothing really addresses what may go wrong.
This SO question:
is specific to ElasticFox and I'm not using any tools (prefer command line). I don't believe the question is answered either.
This blog:
http://instantbadger.blogspot.com/2009/09/how-to-create-and-save-ami-image-from.html
while instructive about creating an AMI, does not mention EBS at all and I'm a little worried about all that data.
Thanks in advance!
Upvotes: 8
Views: 3327
Reputation: 788
as @steenhulthin mentioned you should do the FS Freeze and put database into a readlock mode to take a consistent backup else you will have a crash-consistent only
Types of Backups https://asvignesh.in/backup-types-inconsistent-app-consistent-crash-consistent/
You can have an SSM Command to do the FLUSH and Lock the tables of the databases which will bring you the consistency of the MySQL Data and create an Image from the console and once you trigger the AMI creation you can unlock the tables Make sure you run the Flush tables in the background script, once you close the session the lock will be released in MySQL
You can find the scripts to lock and unlock the table which you can invoke through SSM https://asvignesh.in/mysql-app-consistent-backup-using-nimesa/
Here is the script for just Filesystem freeze https://asvignesh.in/consistent-backup-of-your-ec2-instance/
Upvotes: 0
Reputation: 9415
Amazon console gives you an option to do this STUFF.
Just, login on to your aws console and navigate the instance-ID you wish to create an AMI.
That's it. This would have created an AMI. Please see: http://docs.amazonwebservices.com/AWSEC2/2011-05-15/UserGuide/index.html?Tutorial_CreateImage.html for a detailed information.
Upvotes: 2
Reputation: 3402
Make sure you always backup you MySQL by dumping as suggested by steenhulthin.
This link will help on creating your new EBS backed AMI: http://www.capsunlock.net/2009/12/create-ebs-boot-ami.html
I also suggest to place your MySQL data to a separate EBS volume or better RAIDed volumes.
Upvotes: 1
Reputation: 4773
Before going to your questions I would suggest that you back up your MySQL database to a file which is not stored as a snapshot or in an EBS before you start creating the image. (And of course test that you can restore it to somewhere else than your production system.)
I use:
mysqldump --add-drop-table -u root -p databasename > database.sql
to backup and:
mysql -u root -p databasename < database.sql
to restore.
A bit more info: I prefer to shut down the database when possible when snapshoting or creating images. That said I am not by any mean an MySQL expert, but here is some guidance from http://aws.amazon.com/articles/1663?_encoding=UTF8&jiveRedirect=1
Start a MySQL session on the instance, using the password you set above.
mysql -u root -p
In the mysql session, flush the tables to disk and acquire a lock. Flush the file system to disk and freeze it. Do not exit the MySQL session or you will lose the lock and snapshot potentially inconsistent database files!
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;
SYSTEM sudo xfs_freeze -f /vol
Upvotes: 2