Skip to main content

Restoring an Amazon RDS Instance Using Snapshots

Hands-On Lab

 

Photo of Mark Richman

Mark Richman

AWS Training Architect II in Content

Length

01:30:00

Difficulty

Intermediate

A critical part of database management is being able to recover your data after corruption or accidental deletion has occurred. In this hands-on lab, we'll use the point-in-time restore capability of RDS automated snapshots to restore a database and bring a site back up. NOTE: This lab may take up to 15 minutes to fully start due to the number of resources that need to be provisioned.

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.

Restoring an Amazon RDS Instance Using Snapshots

Introduction

A critical part of database management is being able to recover your data after corruption or accidental deletion has occurred.

In this hands-on lab, we'll use the point-in-time restore capability of RDS automated snapshots to restore a database and bring a site back up.

Solution

Please log in to the lab environment with the cloud_user credentials provided. Make sure you are using us-east-1 region throughout the lab.

Make a note of the cloud_user password for connecting to the bastion instance.

NOTE: This environment will take up to 15 minutes to create.

Open the WordPress Application to Monitor It

  1. Navigate to EC2 > Load Balancers.
  2. With the load balancer selected, copy the DNS name listed below, and paste it into a new browser tab.
  3. Keep this tab open to monitor the application later.

Create an RDS Snapshot

  1. In the AWS console, navigate to RDS.
  2. Click DB Instances, and select the running instance.

NOTE: Copy the endpoint listed and paste it into a text file, as we'll need it for the next step.

  1. Select Actions > Take snapshot.
  2. Name the snapshot (e.g., "wordpress-YYYYMMDD").

Log in to the Bastion Host and Delete Database Data

  1. Navigate to EC2 > Instances.

  2. With the bastion-host instance selected, copy the public IP listed in the Description section.

  3. Open a terminal session, and log in to the bastion host via SSH as cloud_user using the public IP:

    ssh cloud_user@<PUBLIC IP>

    Use the password provided on the lab page — it will be different than the one you used to log in to the AWS console.

  4. Install the MySQL command line:

    sudo yum install mysql
  5. Connect to MySQL (using the RDS endpoint you copied earlier):

    mysql --user=wpuser --password=Password1 --host=<RDS ENDPOINT NAME>
  6. At the MySQL prompt, switch to the WordPress database:

    use wordpressdb;
  7. Delete a critical table:

    drop table wp_posts;
  8. In the browser, refresh the WordPress site, which should result in an error page.

Restore an RDS Database from a Snapshot

  1. In the RDS console, navigate to Snapshots.
  2. Note the snapshot creation time.
  3. Click Databases in the left-hand menu, and select wordpress-database.
  4. Click Actions, and select Restore to point in time.
  5. Select a Custom restore time, and enter the point in time you want to restore from (selecting today's date and a time after the snapshot creation time).
  6. Give it a DB instance identifier of "wordpress-recovery".
  7. Set the Availability zone to us-east-1b.
  8. Click Launch DB Instance. It will take a few minutes for it to become available.

Rename Database Instances

  1. Head back to the Databases dashboard, select wordpress-database, and click Modify.
  2. Change the DB instance identifier from "wordpress-database" to "wordpress-corrupt".
  3. Click Continue.
  4. Select Apply Immediately, and click Modify DB Instance. It will take a minute for it to finish renaming.
  5. Now, select wordpress-recovery, and click Modify.
  6. Change the DB instance identifier from "wordpress-recovery" to "wordpress-database".
  7. Under Security group, delete the default security group and select DatabaseSecurityGroup from the dropdown.
  8. Click Continue.
  9. Select Apply Immediately, and click Modify DB Instance.
  10. Refresh the WordPress website, and observe that the last known good configuration is present.

Conclusion

Congratulations on completing this hands-on lab!