Sure, most people with servers in AWS occasionally take snapshots of their EC2 instances’ root volumes to protect against crashes, corrupt updates, etc., but many new AWS admins never actually attempt to to restore a server’s backed-up root volume from a snapshot until they have to. So, if you’ve never had to do it before, and now a series of panicked web searches has lead you here, then don’t worry – it’s easy to restore the server back to its snapshotted state, even maintaining its original IP address and host name, just like nothing happened. Here’s how…
- Find the instance in EC2 and stop it.
- Make a note of the instance’s Availability Zone, and then scroll down to where it lists the instance’s “Root device” and make a note of what it’s called (it usually is “/dev/sda1”). Now click on the Root device, and in the little window that appears, click on the EBS ID (“vol-xxxxxxxxxxx”).
- You’ll be sent to the EBS Volumes page, filtered to only show the volume you’re interested in. Right-click on the volume name and choose “Detach Volume.”
- Now go to the EBS Snapshots page and find the snapshot you want to use as the new root volume. Right-click on it and choose “Create Volume.”
- In the “Create Volume” page, make sure the availability zone of the volume matches the availability zone that you made a note of in Step 2 (i.e., the EBS volume you create must be in the same AZ as its instance).
- Also, in the “Create Volume” page, be sure to check the box at the bottom to “Add tags to your volume” and then create a “Name” tag with a value of something like: “<instance name> – <device name> (from Step #2 above) – restored <today’s date>”. (So, we’re giving the new volume the same name the original one had when it was created, and appending some info at the end to indicate it’s a restored copy.) When done, click the Create Volume button.
- Once the volume has been created, go back to the EBS Volumes page and right-click on the volume you just created, then choose “Attach Volume.”
- When you click in the “Instance” field, it will bring up a list of instances in your account/region that you can attach it to. Select the instance you’re interested in.
- In the “Device” field, it will make a suggestion for a device name that would make sense if you were adding this volume to the instance as an additional disk, but since we’re making it the root volume, you can ignore the suggested name and enter the name you made a note of in Step #2 above. (e.g., /dev/sda1)
- Once you click the “Attach” button to close that window, it will attach the volume to the instance you specified as the root volume. You can now go back to the “Instances” page and start your instance. If everything went smoothly, the instance will start as normal, like nothing happened. If not, you’ll get a message telling you the instance can’t boot, so check that you entered the correct device name when trying to attach the volume.
- Now that your server is up and running on the new volume, you can do a little housekeeping by going back and deleting the old volume, if you won’t be using it anymore.
That’s it! See, nothing to worry about – it’s easy when you know how! :)