Restore an RDS Instance to a Point in Time using Snapshots
A critical part of database management is being able to recover your data after corruption or accidental deletion has occurred. In this scenario, you are a systems administrator for a company with a corporate website powered by Wordpress. The developer has just contacted you that some unspecified corruption in the database has occurred and now the site is down and the admin panel cannot be reached. Your task will be to use the point-in-time restore capability of RDS automated snapshots to restore the database and bring the 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.
Restore an RDS Instance to a Point in Time Using Snapshots
A critical part of database management is being able to recover your data after corruption or accidental deletion has occurred.
In this lab, we will learn how to create an RDS snapshot and use it to restore an RDS database to a specific point in time.
>Note: Because of the number of resources that must be provisioned, this lab may take up to 15 minutes to spin up.
Log in to the live environment with the credentials provided on the lab instructions page. Make sure you are using us-east-1 as your region throughout the lab.
Create an RDS Snapshot
- In the AWS Management Console, navigate to the EC2 service.
- Click Load Balancers in the left sidebar.
- In the Description tab at the bottom of the page, copy the DNS name to your clipboard.
- Paste the DNS name into a new tab in your browser.
- Go back to your AWS Management Console tab, and navigate to the RDS service.
- Under the Resources header, click DB Instances.
- Click the wordpress-database instance.
- Scroll down to the Snapshots header, and click Take snapshot.
- For Snapshot name, type "wordpress-date".
- Click Take Snapshot.
Corrupt the Database
- Navigate to the EC2 service, and click 3 Running Instances at the top of the page.
- Select the bastion-host.
- In the Description tab at the bottom of the page, copy the IPv4 public IP address.
- Open your terminal application, and log in to the bastion host via SSH.
yesat the prompt.
- Enter the password for the bastion instance at the prompt.
- Go back to the AWS Console and navigate to the RDS service.
- Click DB Instances and then click wordpress-database.
- Locate the endpoint under the Connect header, and copy it to your clipboard.
- Run the following command to connect to the MySQL database running in our private subnet:
mysql --user=wpuser --password=Password1 --host=&#60;WORDPRESS_DATABASE_ENDPOINT&#62;
- Next, we'll tell MySQL to use the wordpress-database instance.
- Then, delete the post table.
drop table wp_posts;
- Go back to our website tab in your browser, and refresh the page. The website should no longer be working properly because we have corrupted the database.
Restore an RDS Database from a Snapshot
- Go back to the AWS Management Console, and click Instances in the sidebar.
- Select the wordpress-database, then click Instance actions and Restore to point in time.
- For Restore time, select Custom.
- Enter today's date and a time between when the snapshot was created and when we corrupted the database.
- Scroll down to the Settings header, and type "wordpress-recovery" for the DB instance identifier.
- Change the Availability zone to us-east-1b.
- Click Launch DB Instance.
- Once the instance is available, select wordpress-database.
- Click Instance actions, then Modify.
- Scroll down to the Settings section, and change DB instance identifier to "wordpress-corrupt".
- Click Continue.
- Select the Apply immediately option, then click Modify DB Instance.
- Repeat steps 9-12 for the wordpress-recovery database, but change two things:
- For DB instance identifier, type "wordpress-database".
- For Security group, select the DatabaseSecurityGroup option from the dropdown.
- Once the wordpress-database is in an available state, go back to our website browser tab and refresh the page. The website should be working properly again, as we have successfully restored the database to a point in time before it was corrupted.
Congratulations, you've successfully completed this lab!