Skip to main content

Restoring EBS Snapshots for Backup Restore

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:

  1. // Stop MySQL
    sudo /etc/init.d/mysql stop
  2. //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 /vol
    sudo mount /vol
  3. // 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
  4. // Recreate the MySQL file structure

    sudo mkdir /mnt/mysql
    sudo mkdir /var/lib/mysql
    sudo mkdir /var/log/mysql
  5. // 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
  6. // Restart MySQL and login to see the original data taken the day of the snapshot.
    sudo /etc/init.d/mysql start

Thanks to This is the original article we setup the server with.