How to Restore AWS RDS from Snapshot Quickly
To restore an AWS RDS database from a snapshot, use the
aws rds restore-db-instance-from-db-snapshot command specifying the snapshot identifier and a new DB instance identifier. This creates a new RDS instance restored to the snapshot state without affecting the original database.Syntax
The basic AWS CLI command to restore an RDS instance from a snapshot is:
--db-instance-identifier: The name for the new database instance you want to create.--db-snapshot-identifier: The identifier of the snapshot you want to restore from.- Optional parameters can include instance class, availability zone, and security groups.
bash
aws rds restore-db-instance-from-db-snapshot \ --db-instance-identifier <new-db-instance-name> \ --db-snapshot-identifier <snapshot-id> \ [--db-instance-class <instance-class>] \ [--availability-zone <zone>] \ [--vpc-security-group-ids <security-group-ids>]
Example
This example restores an RDS instance named mydb-restored from a snapshot called mydb-snapshot-2024-06-01. It specifies the instance class and security group for the new instance.
bash
aws rds restore-db-instance-from-db-snapshot \ --db-instance-identifier mydb-restored \ --db-snapshot-identifier mydb-snapshot-2024-06-01 \ --db-instance-class db.t3.medium \ --vpc-security-group-ids sg-0123456789abcdef0
Output
{
"DBInstance": {
"DBInstanceIdentifier": "mydb-restored",
"DBInstanceStatus": "creating",
"DBInstanceClass": "db.t3.medium",
"Engine": "mysql",
"DBSubnetGroup": {
"DBSubnetGroupName": "default",
"SubnetGroupStatus": "Complete"
},
"VpcSecurityGroups": [
{
"VpcSecurityGroupId": "sg-0123456789abcdef0",
"Status": "active"
}
]
}
}
Common Pitfalls
- Using the same
--db-instance-identifieras an existing instance causes an error; always use a new name. - Not specifying the correct snapshot ID will fail the restore.
- Failing to specify required parameters like instance class can cause the command to fail.
- Restoring into a different VPC or subnet without proper permissions or configuration can cause issues.
bash
Wrong: aws rds restore-db-instance-from-db-snapshot \ --db-instance-identifier mydb \ --db-snapshot-identifier mydb-snapshot-2024-06-01 Right: aws rds restore-db-instance-from-db-snapshot \ --db-instance-identifier mydb-restored \ --db-snapshot-identifier mydb-snapshot-2024-06-01
Quick Reference
Remember these key points when restoring RDS from a snapshot:
- Always use a new DB instance identifier.
- Check snapshot ID carefully.
- Specify instance class and security groups as needed.
- Restored instance is independent of the original.
Key Takeaways
Use a unique new DB instance identifier when restoring from a snapshot.
Specify the correct snapshot ID to avoid restore failures.
Include required parameters like instance class and security groups.
Restoring creates a new independent RDS instance without affecting the original.
Verify network and permission settings if restoring into a different VPC or subnet.