0
0
AWScloud~5 mins

RDS backup and snapshots in AWS - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you run a database in the cloud, you need to save copies of your data to protect it from loss. RDS backups and snapshots let you save your database state so you can restore it if something goes wrong.
When you want to protect your database from accidental deletion or corruption by saving its state regularly.
When you need to create a copy of your database to test changes without affecting the live data.
When you want to move your database to a different region or account safely.
When you want to restore your database to a previous point in time after a failure.
When you want to automate backups to meet compliance or business rules.
Commands
This command creates a manual snapshot of the RDS database named 'mydbinstance'. Snapshots save the current state of the database for later restoration.
Terminal
aws rds create-db-snapshot --db-instance-identifier mydbinstance --db-snapshot-identifier mydbsnapshot1
Expected OutputExpected
{"DBSnapshot":{"DBSnapshotIdentifier":"mydbsnapshot1","DBInstanceIdentifier":"mydbinstance","SnapshotCreateTime":"2024-06-01T12:00:00Z","Status":"creating"}}
--db-instance-identifier - Specifies which database instance to snapshot
--db-snapshot-identifier - Names the snapshot for easy reference
This command checks the status and details of the snapshot named 'mydbsnapshot1' to confirm it was created successfully.
Terminal
aws rds describe-db-snapshots --db-snapshot-identifier mydbsnapshot1
Expected OutputExpected
{"DBSnapshots":[{"DBSnapshotIdentifier":"mydbsnapshot1","DBInstanceIdentifier":"mydbinstance","SnapshotCreateTime":"2024-06-01T12:00:00Z","Status":"available"}]}
--db-snapshot-identifier - Filters the output to show only the specified snapshot
This command creates a new database instance named 'mydbrestored' by restoring the data from the snapshot 'mydbsnapshot1'.
Terminal
aws rds restore-db-instance-from-db-snapshot --db-instance-identifier mydbrestored --db-snapshot-identifier mydbsnapshot1
Expected OutputExpected
{"DBInstance":{"DBInstanceIdentifier":"mydbrestored","DBInstanceStatus":"creating"}}
--db-instance-identifier - Names the new database instance to create
--db-snapshot-identifier - Specifies which snapshot to restore from
This command checks the status of the restored database instance to know when it is ready to use.
Terminal
aws rds describe-db-instances --db-instance-identifier mydbrestored
Expected OutputExpected
{"DBInstances":[{"DBInstanceIdentifier":"mydbrestored","DBInstanceStatus":"available"}]}
--db-instance-identifier - Filters output to the restored instance
Key Concept

If you remember nothing else from this pattern, remember: snapshots save your database state so you can restore it anytime without losing data.

Common Mistakes
Trying to create a snapshot with a name that already exists
AWS will reject the request because snapshot names must be unique per account and region
Use a new, unique snapshot identifier each time you create a snapshot
Restoring a snapshot without specifying a new database instance identifier
The restore command requires a new instance name; it cannot overwrite the original database
Always provide a unique --db-instance-identifier when restoring from a snapshot
Assuming snapshots are automatic backups
Manual snapshots are created only when you run the command; automatic backups are separate and managed by AWS
Use automated backups for regular scheduled backups and manual snapshots for on-demand copies
Summary
Create manual snapshots to save your database state at any time.
Check snapshot status to confirm it is ready before restoring.
Restore a new database instance from a snapshot using a unique name.
Verify the restored instance is available before using it.