Using AWS EBS Snapshots to Restore Files to an AWS EBS Volume

Hands-On Lab

 

Photo of Craig Arcuri

Craig Arcuri

AWS Training Architect II in Content

Length

00:30:00

Difficulty

Advanced

This hands-on lab will walk through the process of restoring files from an EBS Snapshot back to its original location in an EBS Volume. The scenario presented will be the accidental deletion of a file in an EBS Volume. Fortunately, before this deletion occurred a snapshot of the EBS Volume was created. Once the EBS Snapshot is created, the student can work from the AWS Command Line Interface to create a new volume from the snapshot. The new volume can then be attached to the existing EC2 instance. After connecting the volume to the EC2 instance, the file can be restored to its original location on the original EBS volume. This hands-on lab also provides an opportunity to do some work from the AWS CLI.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Using AWS EBS Snapshots to Restore Files to an AWS EBS Volume

Introduction

In this hands-on lab, we will learn how to restore a file from an EBS snapshot to its original location in an EBS volume. This is a useful skill for restoring files after an accidental deletion.

To accomplish this, we will:

  • Create an EBS snapshot
  • Create a new volume from the snapshot
  • Attach the new volume to the existing EC2 instance
  • Restore the file to its original location on the EBS volume

Log in to the AWS Management Console using the credentials provided on the lab instructions page.

Make sure you are using the us-east-1 region.

Create an EBS Snapshot

  1. In the AWS Management Console, navigate to the EC2 service.
  2. Click Running Instances.
  3. In the Description tab at the bottom of the page, copy the IPv4 Public IP address to your clipboard.
  4. Open your terminal application in a new window.
  5. In your terminal window, run the following command:
    ssh linuxacademy@<PUBLIC_IP_ADDRESS>
  6. Type yes at the prompt.
  7. Type 123456 at the password prompt.
  8. Display the file systems and their sizes.
    df -h
  9. Change to the /mnt directory.
    cd /mnt
  10. List the contents of the directory.
    ls
  11. Go back to your AWS Management Console window.
  12. Click Volumes in the left sidebar.
  13. Select the standard volume from the list.
  14. Click Actions > Create Snapshot.
  15. On the Create Snapshot page, type "appname-backup-date" for the Description.
  16. Click Create Snapshot, then Close.
  17. Click Snapshots in the left sidebar.
  18. Go back to your terminal window, and delete the restore-this-file file.
    rm restore-this-file
  19. Type yes at the prompt.
  20. Elevate to admin privileges and run the command again.
    sudo rm restore-this-file
  21. Type 123456 at the password prompt.
  22. List the contents of the directory.
    ls
  23. restore-this-file should no longer appear in the directory.

Create an EBS Volume from the Snapshot

  1. On the Snapshots page of the AWS Management Console, click Actions > Create Volume.
  2. On the Create Volume page, configure the following settings:
    • Volume Type: General Purpose SSD (GP2)
    • Size (GiB): 10
    • Availability Zone: us-east-1a
  3. Click Create Volume, then Close.
  4. Click Snapshots in the left sidebar.
  5. Select the volume we just created (with a status of available) from the list.
  6. Click Actions > Attach Volume.
  7. In the Attach Volume menu, select the WebServer instance from the Instance dropdown.
  8. Click Attach.
  9. Go back to your terminal window.
  10. Elevate to the root user.
    su
  11. Type 123456 at the password prompt.
  12. Change to the /dev directory.
    cd /dev
  13. List the contents of the directory.
    ls
  14. Make a new directory called /restore.
    mkdir /restore
  15. Mount the new volume we created to the /restore directory.
    mount /dev/xvdg1 /restore
  16. Change to the /restore directory.
    cd /restore
  17. List the contents of the directory.
    ls
  18. Copy restore-this-file to its original location.
    cp restore-this-file /mnt/
  19. Change to the /mnt directory.
    cd /mnt
  20. List the contents of the directory.
    ls
  21. restore-this-file should be listed.

Conclusion

Congratulations, you've successfully completed this hands-on lab!