Replace an Amazon EBS volume using a previous snapshot - Amazon EBS

Replace an Amazon EBS volume using a previous snapshot

Amazon EBS snapshots are the preferred backup tool on Amazon EC2 because of their speed, convenience, and cost. When creating a volume from a snapshot, you recreate its state at a specific point in time with the data saved up to that specific point intact. By attaching a volume created from a snapshot to an instance, you can duplicate data across Regions, create test environments, replace a damaged or corrupted production volume in its entirety, or retrieve specific files and directories and transfer them to another attached volume. For more information, see Amazon EBS snapshots.

You can use one of the following procedures to replace an Amazon EBS volume with another volume created from a previous snapshot of that volume.

Console
To replace a volume using the console
  1. Create a volume from the snapshot and write down the ID of the new volume. For more information, see Create a volume from a snapshot.

    Note

    Ensure that you create the volume in the same Availability Zone as the instance. Volumes can only be attached to instances in the same Availability Zone.

  2. On the Instances page, select the instance on which to replace the volume and write down the instance ID.

    With the instance still selected, choose the Storage tab. In the Block devices section, find the volume to replace and write down the device name for the volume, for example /dev/sda1.

    Choose the volume ID.

  3. On the Volumes screen, select the volume and choose Actions, Detach volume, Detach.

  4. Select the new volume that you created in step 1 and choose Actions, Attach volume.

    For Instance and Device name, enter the instance ID and device name that you wrote down in Step 2, and then choose Attach volume.

  5. Connect to your instance and mount the volume. For more information, see Make an Amazon EBS volume available for use.

AWS CLI
To replace a volume using the AWS CLI
  1. Create a new volume from the snapshot. Use the create-volume command. For --snapshot-id, specify the ID of the snapshot to use. For --availability-zone, specify the same Availability Zone as the instance. Configure the remaining parameters as needed.

    Note

    Ensure that you create the volume in the same Availability Zone as the instance. Volumes can only be attached to instances in the same Availability Zone.

    $ aws ec2 create-volume \ --volume-type volume_type \ --size volume_size \ --snapshot-id snapshot_id \ --availability-zone az_id

    In the command output, note the ID of the new volume.

  2. Get the device name of the volume to replace. Use the describe-instances command. For --instance-ids, specify the ID of the instance on which to replace the volume.

    $ aws ec2 describe-instances --instance-ids instance_id

    In BlockDeviceMappings in the command output, note DeviceName and VolumeId for the volume to replace.

  3. Detach the volume to replace from the instance. Use the detach-volume command. For --volume-id, specify the ID of the volume to detach.

    $ aws ec2 detach-volume --volume-id volume_id
  4. Attach the replacement volume to the instance. Use the attach-volume command. For --volume-id, specify the ID of the replacement volume. For --instance-id, specify the ID of the instance to which to attach the volume. For --device, specify the same device name that you noted previously.

    $ aws ec2 attach-volume \ --volume-id volume_id \ --instance-id instance_id \ --device device_name
  5. Connect to your instance and mount the volume. For more information, see Make an Amazon EBS volume available for use.