Migrate data using Amazon EBS to a new running instance in EC2.

Been running mysql server inside Amazon EC2 throught an Elastic Block store and needs to be migrated to a new instance.

The tasks include:

1. Stopping mysql server.

2. Assume /var/lib/mysql and /var/log/mysql are symbolic links to
/ebs1/MYSQLDB/var/lib/mysql and /ebs1/MYSQLDB/var/log/mysq respectively.
Create a snapshot of a volume which is attached to the running instance.

3. Create new Volume from generated snapshot.

4. Install mysql-server. Stop mysql-server first, then

5. Attach new volume to the the new running instance. /dev/sdh and mount to /ebs1 directory.

6. Configure the symlink to /var/log/mysql and /var/lib/mysql point to
/ebs1/MYSQLDB//var/log/mysql and /ebs1/MYSQLDB/var/lib/mysql repectively.

In some cases, I got the error in debian-sys-maint when starting mysql, which can easily fix
by checking the password at /etc/mysql/debian.cnf for Ubuntu machines and granting
admin permissions for this user.

I tried also attaching EBS Volumes with the same data inside and get the error:

   Filesystem "sdi": Disabling barriers, not supported by the underlying device
XFS: Filesystem sdi has duplicate UUID - can't mount
sdi: unknown partition table<br />   

Where my /etc/fstab says:

 # Legacy /etc/fstab
 # Supplied by: ec2-ami-tools-1.3-30748
 /dev/sda1 /     ext3    defaults 1 1
 /dev/sda2 /mnt  ext3    defaults 0 0
 /dev/sda3 swap  swap    defaults 0 0
none      /proc proc    defaults 0 0
none      /sys  sysfs   defaults 0 0
/dev/sdh /ebs1 xfs noatime 0 0
/dev/sdi /ebs2 xfs noatime 0 0

To get the /ebs2 work, I need to add nouuid to fstab options.

   /dev/sdi /ebs2 xfs noatime,nouuid 0 0

http://developer.amazonwebservices.com/connect/thread.jspa?messageID=114594
http://adumont.serveblog.net/2007/03/31/xfs-and-lvm-snapshots/

3 thoughts on “Migrate data using Amazon EBS to a new running instance in EC2.

  1. Alex Dumont

    Through what I understand you’re doing more a clonation than a migration, aren’t you?

    I mean, by cloning ebs1 to ebs2, you end with 2 EBS. What for? Just for rollback purpose in case of failure in your migration process? Or is it in order to run 2 instances of MySQL on the (inicially at least) same set of data?

    Just curious 😉

    Alex

    PS: Didn’t know this EBS thing. I’ll have to investigate. Is it exclusive for EC2 machines or can you attach an EBS to a physical box, at home for example?

  2. rodney Post author

    Hi Alex,

    Thanks for dropping by.

    It’s more of cloning the two EBS containing Mysql data, to run a master-slave setup thing 🙂

    After some more readings, mysql-ec2-ebs tutorial, I’ve realized there’s a xfs snaphot program I can use here to do freeze and create EBS snapshot easily.

    I was testing to attached them on the same EC2 instance :). Attaching the new EBS to another instance works normally though.

    EBS is exclusive to EC2. EBS is like a disk storage device. Hmm.. I/O performance and latency if attach at any local physical machine might be slower but that sounds possible. What do you think of having 1terabyte data volume where you can attached to your laptop anytime and wherever you are? 🙂

    Rodney

Leave a Reply

Your email address will not be published. Required fields are marked *