Creating a snapshot ensures you have a backup of the current RDS state. This snapshot can be used to restore the RDS instance later.
Steps to Create a Snapshot via AWS Management Console:
- Navigate to the RDS Dashboard.
- Select the RDS instance you want to back up.
- Click Actions > Take Snapshot.
- Provide a name for the snapshot (e.g.,
rds-snapshot-test-date
). - Click Take Snapshot.
Automating Snapshot Creation with AWS CLI:
aws rds create-db-snapshot \
--db-snapshot-identifier rds-snapshot-test-date \
--db-instance-identifier your-rds-instance-id
Step 2: Use the RDS Instance for Testing
Once the snapshot is created, continue using the RDS instance for your testing activities for the day. Ensure you document any changes made during testing, as these will not persist after restoring the instance from the snapshot.
Step 3: Rename and Delete the RDS Instance
At the end of the day, rename the existing RDS instance and delete it to avoid unnecessary costs.
Steps to Rename the RDS Instance via AWS Management Console:
- Navigate to the RDS Dashboard.
- Select the RDS instance.
- Click Actions > Modify.
- Update the DB Instance Identifier (e.g.,
rds-instance-test-old
). - Save the changes and wait for the instance to update.
Steps to Delete the RDS Instance:
- Select the renamed instance.
- Click Actions > Delete.
- Optionally, skip creating a final snapshot if you already have one.
- Confirm the deletion.
Automating Rename and Delete via AWS CLI:
# Rename the RDS instance
aws rds modify-db-instance \
--db-instance-identifier your-rds-instance-id \
--new-db-instance-identifier rds-instance-test-old
# Delete the RDS instance
aws rds delete-db-instance \
--db-instance-identifier rds-instance-test-old \
--skip-final-snapshot
Step 4: Restore the RDS Instance from the Snapshot
Before starting the next day’s testing, restore the RDS instance from the snapshot created earlier.
Steps to Restore an RDS Instance via AWS Management Console:
- Navigate to the Snapshots section in the RDS Dashboard.
- Select the snapshot you want to restore.
- Click Actions > Restore Snapshot.
- Provide a new identifier for the RDS instance (e.g.,
rds-instance-test
). - Configure additional settings if needed and click Restore DB Instance.
Automating Restore via AWS CLI:
aws rds restore-db-instance-from-db-snapshot \
--db-instance-identifier rds-instance-test \
--db-snapshot-identifier rds-snapshot-test-date
Optional: Automate the Process with a Script
To streamline these steps, you can use a script combining AWS CLI commands. Below is an example script:
#!/bin/bash
# Variables
RDS_INSTANCE_ID="your-rds-instance-id"
SNAPSHOT_ID="rds-snapshot-$(date +%F)"
RESTORED_RDS_INSTANCE_ID="rds-instance-test"
# Step 1: Create a Snapshot
echo "Creating snapshot..."
aws rds create-db-snapshot \
--db-snapshot-identifier $SNAPSHOT_ID \
--db-instance-identifier $RDS_INSTANCE_ID
# Step 2: Rename and Delete RDS Instance
echo "Renaming and deleting RDS instance..."
aws rds modify-db-instance \
--db-instance-identifier $RDS_INSTANCE_ID \
--new-db-instance-identifier "${RDS_INSTANCE_ID}-old"
aws rds delete-db-instance \
--db-instance-identifier "${RDS_INSTANCE_ID}-old" \
--skip-final-snapshot
# Step 3: Restore RDS from Snapshot
echo "Restoring RDS instance from snapshot..."
aws rds restore-db-instance-from-db-snapshot \
--db-instance-identifier $RESTORED_RDS_INSTANCE_ID \
--db-snapshot-identifier $SNAPSHOT_ID
Top comments (0)