loading...

AWS – Restoring an RDS database from a snapshot

How to create virtual machines with VirtualBox

We’ll now talk through how to restore a database from a snapshot. This process creates a new database that will retain a majority of the configuration of the database that the snapshot was taken from.

Getting ready

You’ll need the following pieces of information:

  • The ID of the snapshot you wish to restore from
  • A name or identifier that you wish to give to the database we’re about to create
AWS does not allow RDS services in your account to share the same identifier. If the source database is still online, you’ll need to make sure to choose a different identifier (or rename the source database).

How to do it…

Follow these steps to restore an RDS snapshot:

  1. Type the following command:
      aws rds restore-db-instance-from-db-snapshot \
        --db-snapshot-identifier <name-of-snapshot-to-restore > \
        --db-instance-identifier <name-for-new-db> \
        --db-subnet-group-name <your-db-subnet-group> \
        --multi-az
  1. You may have noticed that this command creates a new database in the default security group. This happens because restore-db-instance-from-db-snapshot doesn’t accept a security group ID as a parameter. You’ll have to run a second command to assign a non-default security group to the new database:
      aws rds modify-db-instance \
        --db-instance-identifier <name-of-newly-restored-db> \
        --vpc-security-group-ids <id-of-security-group>
The modify-db-instance command will return an error unless the state of the target database is available.

Also, security group names aren’t valid with this command; you’ll need to use a security group ID instead, for example, sg-7603d50a.

How it works…

RDS backups use the snapshot process to make a copy of the entire database instance, not just individual databases or schemas. When restoring the snapshot, you must create a new instance instead of restoring to the original instance. Be sure to associate the restored instance with the original parameter group so that the correct settings are applied to the instance. 

There’s more…

The restore-db-instance-from-db-snapshot command includes the parameter for enabling multi-AZ on the new DB. If you’d like the new DB to be running in single-AZ mode only, then can you simply remove this flag.

Comments are closed.

loading...