Managing Amazon Aurora RDS Snapshots with AWS CLI

Amazon Aurora, a managed relational database service designed for performance and reliability, allows for easy backup and snapshot…

Managing Amazon Aurora RDS Snapshots with AWS CLI
Photo by Mehmet Ali Peker on Unsplash

Amazon Aurora, a managed relational database service designed for performance and reliability, allows for easy backup and snapshot management. Using Amazon RDS snapshots, you can create point-in-time backups of your Aurora clusters, restore data, and manage backups effectively. In this article, we’ll explore how to use the AWS CLI to manage Amazon Aurora DB cluster snapshots, covering how to list, create, view, and delete snapshots.

Prerequisites

  1. AWS CLI: Ensure the AWS CLI is installed and configured on your machine. If not, install it from AWS CLI installation guide.
  2. IAM Permissions: You need permissions for Amazon RDS operations on snapshots (describe, create, and delete).

Step 1: List All Aurora DB Cluster Snapshots

To manage your snapshots effectively, start by listing all existing DB cluster snapshots. This is useful to see available snapshots and their statuses.

Command to List All Snapshots

aws rds describe-db-cluster-snapshots \ 
--query "DBClusterSnapshots[*].[DBClusterSnapshotIdentifier, DBClusterIdentifier, SnapshotCreateTime, Status, Engine]" \ 
--output table

This command retrieves a list of all DB cluster snapshots and provides details like:

  • DBClusterSnapshotIdentifier: The unique identifier of each snapshot.
  • DBClusterIdentifier: The Aurora DB cluster associated with each snapshot.
  • SnapshotCreateTime: When the snapshot was created.
  • Status: The current status, such as available or creating.
  • Engine: The database engine (e.g., aurora, aurora-mysql, or aurora-postgresql).

Example Output

----------------------------------------------------------------------- 
| DBClusterSnapshotIdentifier       | DBClusterIdentifier  | SnapshotCreateTime   | Status    | Engine        | 
----------------------------------------------------------------------- 
| snapshot-2024-11-05-12-00         | aurora-cluster-1     | 2024-11-05T12:00:00Z | available | aurora        | 
| snapshot-2024-11-04-15-00         | aurora-cluster-1     | 2024-11-04T15:00:00Z | available | aurora-mysql  | 
| snapshot-2024-11-03-09-30         | aurora-cluster-2     | 2024-11-03T09:30:00Z | creating  | aurora        | 
-----------------------------------------------------------------------

Tip: To limit the list to snapshots for a specific Aurora DB cluster, use the --db-cluster-identifier parameter:

aws rds describe-db-cluster-snapshots \ 
--db-cluster-identifier "<YourDBClusterIdentifier>" --output table

Step 2: Create a New Snapshot of an Aurora DB Cluster

Creating manual snapshots is helpful for preserving the state of your database at a particular point in time, especially before making significant changes.

Command to Create a New Snapshot

aws rds create-db-cluster-snapshot \ 
--db-cluster-identifier "<YourDBClusterIdentifier>" \ 
--db-cluster-snapshot-identifier "<NewSnapshotName>"
  • db-cluster-identifier: The identifier of the Aurora DB cluster you want to snapshot.
  • db-cluster-snapshot-identifier: The unique name you’d like to assign to the new snapshot.

Example

aws rds create-db-cluster-snapshot \ 
--db-cluster-identifier "aurora-cluster-1" \ 
--db-cluster-snapshot-identifier "manual-snapshot-2024-11-05"

This command creates a snapshot named manual-snapshot-2024-11-05 for the Aurora cluster aurora-cluster-1.

Checking Snapshot Status

To verify the creation status of your snapshot, use the following command:

aws rds describe-db-cluster-snapshots \ 
--db-cluster-snapshot-identifier "<NewSnapshotName>" \ 
--query "DBClusterSnapshots[0].Status" --output text

This will display the snapshot’s status, which will initially be creating and change to available once completed.

Step 3: View Details of a Specific Snapshot

For a detailed view of a specific snapshot, such as engine type, storage size, and encryption status, use the describe-db-cluster-snapshots command.

Command to View Snapshot Details

aws rds describe-db-cluster-snapshots \ 
--db-cluster-snapshot-identifier "<SnapshotIdentifier>" \ 
--output json

This command will return detailed JSON-formatted information about the specified snapshot.

Key Details to Look For:

  • Engine: The database engine version.
  • AllocatedStorage: The storage size of the snapshot.
  • SnapshotType: The type of snapshot (manual or automated).
  • Encrypted: Whether the snapshot is encrypted.

Example

aws rds describe-db-cluster-snapshots \ 
--db-cluster-snapshot-identifier "manual-snapshot-2024-11-05" \ 
--output json

Step 4: Delete an Aurora DB Cluster Snapshot

When you no longer need a snapshot, delete it to avoid unnecessary storage costs. Caution: Snapshot deletion is permanent and cannot be undone.

Command to Delete a Snapshot

aws rds delete-db-cluster-snapshot \ 
--db-cluster-snapshot-identifier "<SnapshotIdentifier>"
  • db-cluster-snapshot-identifier: The identifier of the snapshot to delete.

Example

aws rds delete-db-cluster-snapshot \  
--db-cluster-snapshot-identifier "manual-snapshot-2024-11-05"

This command deletes the manual-snapshot-2024-11-05 snapshot.

Confirm Deletion by Listing Snapshots

To confirm that the snapshot has been deleted, list all snapshots again and ensure that it no longer appears:

aws rds describe-db-cluster-snapshots \ 
--query "DBClusterSnapshots[*].[DBClusterSnapshotIdentifier, DBClusterIdentifier, SnapshotCreateTime, Status]" \ 
--output table

Summary of Commands

Here’s a quick reference for managing Aurora DB cluster snapshots:

List All Snapshots:

aws rds describe-db-cluster-snapshots \ 
--query "DBClusterSnapshots[*].[DBClusterSnapshotIdentifier, DBClusterIdentifier, SnapshotCreateTime, Status, Engine]" \ 
--output table

Create a New Snapshot:

aws rds create-db-cluster-snapshot \ 
--db-cluster-identifier "<YourDBClusterIdentifier>" \ 
--db-cluster-snapshot-identifier "<NewSnapshotName>"

View Snapshot Details:

aws rds describe-db-cluster-snapshots \ 
--db-cluster-snapshot-identifier "<SnapshotIdentifier>" \ 
--output json

Delete a Snapshot:

aws rds delete-db-cluster-snapshot \ 
--db-cluster-snapshot-identifier "<SnapshotIdentifier>"

Best Practices

  • Automate Backups: Schedule automated snapshots to ensure regular backups. Manual snapshots are best for important checkpoints before making changes.
  • Monitor Snapshot Status: Use scripts to monitor the creation and deletion of snapshots.
  • Review Storage Costs: Regularly review your snapshots to delete any that are no longer needed and control storage costs.

By using the AWS CLI to manage Amazon Aurora snapshots, you have direct control over your database backups, allowing for efficient and cost-effective management.

In Plain English 🚀

Thank you for being a part of the In Plain English community! Before you go: