Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you have a running EC2 instance, and you want to restore it to the state captured in an earlier snapshot, then you need to stop the instance, detach its current volume, create a new volume from the snapshot, attach the new volume to your instance, and restart your instance. Furthermore, there are a couple subtleties around specifying the availability zone of the new volume, and the device name when detaching/re-attaching the volume.</p> <p>The logic might easier to see if you do it from the command line, instead of from the AWS web UI.</p> <p>The following bash script is <strong>not fit for production use</strong>, since it lacks any error-checking and it just uses <code>sleep</code> instead of polling to ensure AWS commands have completed. But it does perform all these steps successfully:</p> <pre><code>#!/bin/bash set -e # IN PARAMS INSTANCE_ID=&lt;YOUR_INSTANCE_ID_HERE&gt; SNAPSHOT_ID=&lt;YOUR_SNAPSHOT_ID_HERE&gt; # OUT PARAMS VOLUME_ID= # begin execution echo "Gathering information about the instance" DEVICE_NAME=`ec2-describe-instance-attribute ${INSTANCE_ID} --block-device-mapping | awk '{print $2}'` OLD_VOLUME_ID=`ec2-describe-instance-attribute ${INSTANCE_ID} --block-device-mapping | awk '{print $3}'` echo "Found instance ${INSTANCE_ID} has volume ${OLD_VOLUME_ID} on device ${DEVICE_NAME}" echo "Creating new volume from snapshot" AVAILABILITY_ZONE=`ec2-describe-availability-zones --filter state=available | head -n 1 | awk '{print $2}'` VOLUME_ID=`ec2-create-volume --availability-zone ${AVAILABILITY_ZONE} --snapshot ${SNAPSHOT_ID} | awk '{print $2}'` echo "Created new volume: ${VOLUME_ID}" sleep 20 echo "Stopping the instance" ec2-stop-instances $INSTANCE_ID sleep 20 echo "Detaching current volume" ec2-detach-volume $OLD_VOLUME_ID --instance $INSTANCE_ID --device $DEVICE_NAME sleep 20 echo "Attaching new volume" ec2-attach-volume $VOLUME_ID --instance $INSTANCE_ID --device $DEVICE_NAME sleep 20 echo "Starting the instance" ec2-start-instances $INSTANCE_ID </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload