|
| 1 | +# Create a backup vault and backup plan with AWS Backup |
| 2 | + |
| 3 | +This tutorial shows you how to create a backup vault, create a backup plan with a daily schedule and 30-day retention, inspect the plan details, and list your vaults and plans. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- AWS CLI configured with credentials and a default region |
| 8 | +- Permissions for `backup:CreateBackupVault`, `backup:DeleteBackupVault`, `backup:CreateBackupPlan`, `backup:DeleteBackupPlan`, `backup:GetBackupPlan`, `backup:ListBackupVaults`, `backup:ListBackupPlans` |
| 9 | + |
| 10 | +## Step 1: Create a backup vault |
| 11 | + |
| 12 | +Create a vault to store recovery points. |
| 13 | + |
| 14 | +```bash |
| 15 | +VAULT_NAME="tut-vault-$(openssl rand -hex 4)" |
| 16 | + |
| 17 | +aws backup create-backup-vault --backup-vault-name "$VAULT_NAME" \ |
| 18 | + --query 'BackupVaultArn' --output text |
| 19 | +``` |
| 20 | + |
| 21 | +A backup vault is a container for recovery points (backups). Each vault has its own encryption key and access policy. The default vault uses the AWS managed key for Backup. |
| 22 | + |
| 23 | +## Step 2: Create a backup plan |
| 24 | + |
| 25 | +Create a plan with a daily backup rule that targets the vault and retains backups for 30 days. |
| 26 | + |
| 27 | +```bash |
| 28 | +PLAN_NAME="tut-plan-$(openssl rand -hex 4)" |
| 29 | + |
| 30 | +PLAN_RESULT=$(aws backup create-backup-plan --backup-plan "{ |
| 31 | + \"BackupPlanName\":\"$PLAN_NAME\", |
| 32 | + \"Rules\":[{ |
| 33 | + \"RuleName\":\"DailyBackup\", |
| 34 | + \"TargetBackupVaultName\":\"$VAULT_NAME\", |
| 35 | + \"ScheduleExpression\":\"cron(0 12 * * ? *)\", |
| 36 | + \"StartWindowMinutes\":60, |
| 37 | + \"CompletionWindowMinutes\":180, |
| 38 | + \"Lifecycle\":{\"DeleteAfterDays\":30} |
| 39 | + }] |
| 40 | +}") |
| 41 | +PLAN_ID=$(echo "$PLAN_RESULT" | python3 -c "import sys,json;print(json.load(sys.stdin)['BackupPlanId'])") |
| 42 | +``` |
| 43 | + |
| 44 | +`ScheduleExpression` uses a cron expression — this one runs daily at noon UTC. `StartWindowMinutes` is how long Backup waits before canceling a job that hasn't started. `Lifecycle` controls retention. |
| 45 | + |
| 46 | +## Step 3: Describe the plan |
| 47 | + |
| 48 | +View the plan details and rule configuration. |
| 49 | + |
| 50 | +```bash |
| 51 | +aws backup get-backup-plan --backup-plan-id "$PLAN_ID" \ |
| 52 | + --query 'BackupPlan.{Name:BackupPlanName,Rules:Rules[0].{Rule:RuleName,Schedule:ScheduleExpression,Retention:Lifecycle.DeleteAfterDays}}' \ |
| 53 | + --output table |
| 54 | +``` |
| 55 | + |
| 56 | +A plan can have multiple rules targeting different vaults or schedules. Each rule can also specify copy actions to replicate backups to another Region. |
| 57 | + |
| 58 | +## Step 4: List backup vaults |
| 59 | + |
| 60 | +List vaults in your account. |
| 61 | + |
| 62 | +```bash |
| 63 | +aws backup list-backup-vaults \ |
| 64 | + --query 'BackupVaultList[].{Name:BackupVaultName,Created:CreationDate,RecoveryPoints:NumberOfRecoveryPoints}' \ |
| 65 | + --output table |
| 66 | +``` |
| 67 | + |
| 68 | +Every account has a `Default` vault created automatically. The tutorial vault will show zero recovery points since no backup has run yet. |
| 69 | + |
| 70 | +## Step 5: List backup plans |
| 71 | + |
| 72 | +List plans in your account. |
| 73 | + |
| 74 | +```bash |
| 75 | +aws backup list-backup-plans \ |
| 76 | + --query 'BackupPlansList[].{Name:BackupPlanName,Id:BackupPlanId,Created:CreationDate}' \ |
| 77 | + --output table |
| 78 | +``` |
| 79 | + |
| 80 | +Plans are independent of resource assignments. To actually back up resources, you create a backup selection that assigns resources (by ARN or tag) to a plan. |
| 81 | + |
| 82 | +## Cleanup |
| 83 | + |
| 84 | +Delete the backup plan and vault: |
| 85 | + |
| 86 | +```bash |
| 87 | +aws backup delete-backup-plan --backup-plan-id "$PLAN_ID" |
| 88 | +aws backup delete-backup-vault --backup-vault-name "$VAULT_NAME" |
| 89 | +``` |
| 90 | + |
| 91 | +No actual backup ran during this tutorial, so there is no cost. AWS Backup charges only when backups are stored — pricing varies by resource type and storage amount. Deleting the plan stops future scheduled backups, and deleting an empty vault is immediate. |
| 92 | + |
| 93 | +The script automates all steps including cleanup: |
| 94 | + |
| 95 | +```bash |
| 96 | +bash aws-backup-gs.sh |
| 97 | +``` |
| 98 | + |
| 99 | +## Related resources |
| 100 | + |
| 101 | +- [Getting started with AWS Backup](https://docs.aws.amazon.com/aws-backup/latest/devguide/getting-started.html) |
| 102 | +- [Creating a backup plan](https://docs.aws.amazon.com/aws-backup/latest/devguide/creating-a-backup-plan.html) |
| 103 | +- [AWS Backup pricing](https://aws.amazon.com/backup/pricing/) |
| 104 | +- [Supported resources](https://docs.aws.amazon.com/aws-backup/latest/devguide/whatisbackup.html#supported-resources) |
0 commit comments