tags:

views:

202

answers:

0

I'm using Amazon EC2 and am switching from one server instance to another. My original instance has an EBS volume (e.g. hard drive) with the mysql data on it. I want to attach that volume to my new server instance. To originally create the volume I executed the following:

apt-get update && apt-get upgrade -y 
apt-get install -y xfsprogs mysql-server
mkfs.xfs /dev/sdh
echo "/dev/sdh /vol xfs noatime 0 0" >> /etc/fstab
mkdir /vol
mount /vol
/etc/init.d/mysql stop
mkdir /vol/lib /vol/log
mv /var/lib/mysql /vol/lib/
mv /var/log/mysql /vol/log/
test -f /vol/log/mysql/mysql-bin.index &&
  perl -pi -e 's%/var/log/%/vol/log/%' /vol/log/mysql/mysql-bin.index
cat > /etc/mysql/conf.d/mysql-ec2.cnf <<EOM
[mysqld]
innodb_file_per_table
datadir          = /vol/lib/mysql
log_bin          = /vol/log/mysql/mysql-bin.log
max_binlog_size  = 1000M
EOM
rsync -aR /etc/mysql /vol/
/etc/init.d/mysql start

Those commands also work on the new server instance if I start with a blank volume.

However, I want to attach the existing volume to my new instance and configure MySql to use it. I tried the following, but MySql won't restart after I do it.

apt-get update && apt-get upgrade -y
apt-get install -y xfsprogs   
echo "/dev/sdh /vol xfs noatime 0 0" >> /etc/fstab      
mkdir /vol
mount /vol
/etc/init.d/mysql stop  
cat > /etc/mysql/conf.d/mysql-ec2.cnf <<EOM
[mysqld]
innodb_file_per_table
datadir          = /vol/lib/mysql
log_bin          = /vol/log/mysql/mysql-bin.log
max_binlog_size  = 1000M
EOM
rsync -aR /etc/mysql /vol/
/etc/init.d/mysql start

I'm trying to configure this using a script so any new server instances can be configured on the fly. Therefore, I don't want to start with a blank drive and create the database from a backup. Does anyone know what I'm doing wrong? Both servers are running Ubuntu 8.04 and MySql 5.