How to Set Backup Retention Period for AWS RDS Instances
To set the backup retention period for an AWS RDS instance, use the
BackupRetentionPeriod parameter when creating or modifying the instance. This value defines how many days automated backups are kept, ranging from 0 (no backups) to 35 days.Syntax
The BackupRetentionPeriod parameter specifies the number of days to retain automated backups for an RDS instance.
- Value range: 0 to 35 days
- 0 means: automated backups are disabled
- Used in: AWS CLI, AWS Console, CloudFormation, Terraform
bash
aws rds modify-db-instance \
--db-instance-identifier mydbinstance \
--backup-retention-period 7Example
This example shows how to set the backup retention period to 7 days for an existing RDS instance using AWS CLI.
bash
aws rds modify-db-instance \
--db-instance-identifier mydbinstance \
--backup-retention-period 7 \
--apply-immediatelyOutput
An immediate modification is applied to the DB instance 'mydbinstance'. Automated backups will be retained for 7 days.
Common Pitfalls
- Setting
BackupRetentionPeriodto 0 disables automated backups, which means no point-in-time recovery. - Retention period cannot exceed 35 days; setting a higher value causes errors.
- Changes without
--apply-immediatelymay delay backup retention update until the next maintenance window.
bash
aws rds modify-db-instance \
--db-instance-identifier mydbinstance \
--backup-retention-period 40
# Wrong: 40 exceeds max allowed days
aws rds modify-db-instance \
--db-instance-identifier mydbinstance \
--backup-retention-period 7 \
--apply-immediately
# Correct: sets retention to 7 days immediatelyQuick Reference
| Parameter | Description | Value Range | Notes |
|---|---|---|---|
| BackupRetentionPeriod | Days to keep automated backups | 0-35 | 0 disables backups |
| --apply-immediately | Apply changes immediately | true/false | Without it, changes wait for maintenance window |
| DBInstanceIdentifier | Name of the RDS instance | string | Unique identifier of your DB instance |
Key Takeaways
Set BackupRetentionPeriod between 0 and 35 days to control automated backup duration.
A value of 0 disables automated backups and point-in-time recovery.
Use --apply-immediately to update backup retention without waiting for maintenance.
Backup retention changes can be made via AWS CLI, Console, or Infrastructure as Code.
Always verify retention settings to ensure backups meet your recovery needs.