Today I had the unfortunate need to get a restored database from an Amazon EBS snapshot. To do this I logged into the Amazon AWS management console and determined which snapshot I needed to restore from. Once I highlighted the correct snapshot, I clicked the 'Create Volume' button. Next, I chose which availability zone the snapshot should reside in and click 'Create'
Next, I spun up a new instance of the production server, using the same AMI (ami-294aa340). Once the new instance was created, I attached the volume I created above to the instance and logged into the server.
To recreate the production server environment to allow MySQL to access the backed up data I followed the following steps:
// Stop MySQL sudo /etc/init.d/mysql stop
- //Add the drive to /etc/fstab. Note the 'sdf' needs to correspond to what was chosen when the volume was attached earlier
sudo echo "/dev/sdf /vol xfs noatime 0 0" | sudo tee -a /etc/fstab
// Create our /vol mount point directory.sudo mkdir -m 000 /vol
// Mount /volsudo mount /vol
- // Move the original MySQL data directories to a backup file.
sudo mv /mnt/mysql /mnt/mysql.bak sudo mv /mnt/mysql /mnt/mysql.bak sudo mv /var/lib/mysql /var/lib/mysql.bak sudo mv /var/log/mysql /var/log/mysql.bak
- // Recreate the MySQL file structure
sudo mkdir /mnt/mysql sudo mkdir /var/lib/mysql sudo mkdir /var/log/mysql
- // Add the MySQL drives to fstab and mount the drives.
sudo echo "/vol/etc/mysql /mnt/mysql none bind" | sudo tee -a /etc/fstab sudo mount /mnt/mysql sudo echo "/vol/lib/mysql /var/lib/mysql none bind" | sudo tee -a /etc/fstab sudo mount /var/lib/mysql sudo echo "/vol/log/mysql /var/log/mysql none bind" | sudo tee -a /etc/fstab sudo mount /var/log/mysql
- // Restart MySQL and login to see the original data taken the day of the snapshot.
sudo /etc/init.d/mysql start