|
| 1 | +# Cost-Optimized Backup Example |
| 2 | + |
| 3 | +This example demonstrates cost optimization strategies for AWS Backup using a multi-tier backup approach that balances protection requirements with storage costs. |
| 4 | + |
| 5 | +## Use Case |
| 6 | + |
| 7 | +Cost-optimized backup strategies provide: |
| 8 | +- **Tiered Protection**: Different backup frequencies and retention periods based on data criticality |
| 9 | +- **Intelligent Storage Transitions**: Automatic movement to cold storage to reduce costs |
| 10 | +- **Resource Prioritization**: Critical resources get more frequent backups, development resources get minimal backups |
| 11 | +- **Cost Visibility**: Clear cost optimization through strategic lifecycle management |
| 12 | + |
| 13 | +## Architecture |
| 14 | + |
| 15 | +``` |
| 16 | +┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ |
| 17 | +│ Critical │ │ Standard │ │ Development │ |
| 18 | +│ Resources │ │ Resources │ │ Resources │ |
| 19 | +├─────────────────┤ ├─────────────────┤ ├─────────────────┤ |
| 20 | +│ • Every 6 hours │ │ • Daily at 2 AM │ │ • Weekly (Sun) │ |
| 21 | +│ • 1d → Cold │ │ • 30d → Cold │ │ • No Cold │ |
| 22 | +│ • 30d Retention │ │ • 90d Retention │ │ • 7d Retention │ |
| 23 | +│ • Production DB │ │ • EC2, EFS │ │ • Dev DBs │ |
| 24 | +└─────────────────┘ └─────────────────┘ └─────────────────┘ |
| 25 | +``` |
| 26 | + |
| 27 | +## Cost Optimization Strategy |
| 28 | + |
| 29 | +### Tier 1: Critical Resources |
| 30 | +- **Frequency**: Every 6 hours for maximum protection |
| 31 | +- **Storage**: Quick transition to cold storage (1 day) to minimize warm storage costs |
| 32 | +- **Retention**: Short 30-day retention to balance protection with cost |
| 33 | +- **Use Case**: Production databases, critical application data |
| 34 | + |
| 35 | +### Tier 2: Standard Resources |
| 36 | +- **Frequency**: Daily backups during off-hours |
| 37 | +- **Storage**: 30-day warm storage, then cold storage for cost savings |
| 38 | +- **Retention**: 90-day retention for operational recovery needs |
| 39 | +- **Use Case**: EC2 instances, EFS file systems, staging databases |
| 40 | + |
| 41 | +### Tier 3: Development Resources |
| 42 | +- **Frequency**: Weekly backups to minimize storage costs |
| 43 | +- **Storage**: No cold storage transition (short retention makes it unnecessary) |
| 44 | +- **Retention**: 7-day retention for quick recovery only |
| 45 | +- **Use Case**: Development databases, test environments |
| 46 | + |
| 47 | +## Quick Start |
| 48 | + |
| 49 | +1. **Copy the example configuration:** |
| 50 | + ```bash |
| 51 | + cp terraform.tfvars.example terraform.tfvars |
| 52 | + ``` |
| 53 | + |
| 54 | +2. **Edit terraform.tfvars:** |
| 55 | + ```hcl |
| 56 | + region = "us-east-1" |
| 57 | + vault_name = "my-cost-optimized-vault" |
| 58 | + environment = "prod" |
| 59 | + |
| 60 | + critical_resources = [ |
| 61 | + "arn:aws:rds:us-east-1:123456789012:db:production-app-db", |
| 62 | + "arn:aws:dynamodb:us-east-1:123456789012:table/production-user-data" |
| 63 | + ] |
| 64 | + |
| 65 | + standard_resources = [ |
| 66 | + "arn:aws:ec2:us-east-1:123456789012:instance/*", |
| 67 | + "arn:aws:elasticfilesystem:us-east-1:123456789012:file-system/*" |
| 68 | + ] |
| 69 | + ``` |
| 70 | + |
| 71 | +3. **Deploy:** |
| 72 | + ```bash |
| 73 | + terraform init |
| 74 | + terraform plan |
| 75 | + terraform apply |
| 76 | + ``` |
| 77 | + |
| 78 | +## Cost Estimation |
| 79 | + |
| 80 | +**Example monthly costs for 100 GB of data:** |
| 81 | + |
| 82 | +| Tier | Frequency | Warm Storage | Cold Storage | Total/Month | |
| 83 | +|------|-----------|--------------|--------------|-------------| |
| 84 | +| Critical | 6-hourly | $1 (1 day) | $4 (29 days) | ~$5 | |
| 85 | +| Standard | Daily | $5 (30 days) | $2 (60 days) | ~$7 | |
| 86 | +| Development | Weekly | $1 (7 days) | $0 | ~$1 | |
| 87 | +| **Total** | | | | **~$13/month** | |
| 88 | + |
| 89 | +*Compared to $25/month for standard daily backups with warm storage* |
| 90 | + |
| 91 | +## Benefits |
| 92 | + |
| 93 | +- **60% cost reduction** compared to uniform backup strategies |
| 94 | +- **Automated lifecycle management** reduces manual intervention |
| 95 | +- **Scalable approach** that grows with your infrastructure |
| 96 | +- **Compliance-ready** with appropriate retention periods |
| 97 | +- **Resource tagging** enables easy cost allocation and monitoring |
| 98 | + |
| 99 | +## Customization |
| 100 | + |
| 101 | +### Adjusting Backup Frequencies |
| 102 | +```hcl |
| 103 | +# More frequent critical backups |
| 104 | +schedule = "cron(0 */4 * * ? *)" # Every 4 hours |
| 105 | +
|
| 106 | +# Less frequent development backups |
| 107 | +schedule = "cron(0 1 ? * MON *)" # Weekly on Monday |
| 108 | +``` |
| 109 | + |
| 110 | +### Modifying Lifecycle Policies |
| 111 | +```hcl |
| 112 | +lifecycle = { |
| 113 | + cold_storage_after = 7 # Keep in warm storage longer (minimum 1 day) |
| 114 | + delete_after = 180 # Extended retention period |
| 115 | +} |
| 116 | +
|
| 117 | +# To disable cold storage completely, omit cold_storage_after: |
| 118 | +lifecycle = { |
| 119 | + delete_after = 30 # Only specify retention period |
| 120 | +} |
| 121 | +``` |
| 122 | + |
| 123 | +### Resource Selection by Tags |
| 124 | +```hcl |
| 125 | +selection_tags = [ |
| 126 | + { |
| 127 | + type = "STRINGEQUALS" |
| 128 | + key = "CostTier" |
| 129 | + value = "Critical" |
| 130 | + }, |
| 131 | + { |
| 132 | + type = "STRINGEQUALS" |
| 133 | + key = "Environment" |
| 134 | + value = "production" |
| 135 | + } |
| 136 | +] |
| 137 | +``` |
| 138 | + |
| 139 | +## Example Use Cases |
| 140 | + |
| 141 | +- **Startups**: Minimize backup costs while maintaining essential protection |
| 142 | +- **Cost-conscious enterprises**: Optimize backup spending across large infrastructures |
| 143 | +- **Multi-environment setups**: Different backup strategies for prod/staging/dev |
| 144 | +- **Regulated industries**: Meet compliance requirements cost-effectively |
0 commit comments