Sub topic 11
Restoring a resource and verifying it
A backup you have never restored is an untested assumption. This chapter covers how AWS Backup restores a recovery point, how to run a restore from the CLI, and how to check that the result is usable.
It assumes you have read the earlier chapters on vaults, the service role, and recovery points. You should also be comfortable with the AWS CLI, JSON, and the basics of EBS volumes and EC2.
How a restore works
A restore never overwrites the original resource. AWS Backup reads a recovery point and creates a new resource from it: a new EBS volume, a new RDS instance, a new DynamoDB table, and so on. You decide afterwards whether to swap it in for the original.
Each restore is tracked as a restore job. The job reads the recovery point, uses the IAM role you supply, and reports a status and the ARN of the resource it created.
Step 1: choose a recovery point
List the recovery points in the vault and pick one. The most recent one is not always the right one. If the data was corrupted two days ago, you want a point from before that.
aws backup list-recovery-points-by-backup-vault \
--backup-vault-name app-vault \
--query 'RecoveryPoints[].[RecoveryPointArn,ResourceType,CreationDate,Status]' \
--output tableOnly recovery points with status COMPLETED can be restored. A point in PARTIAL or EXPIRED status cannot. Note the ResourceType, because it determines which metadata keys the restore needs.
Step 2: read the restore metadata
Each resource type needs different parameters, such as the Availability Zone for a volume or the subnet group for a database. AWS Backup records the original values, and you can read them back.
aws backup get-recovery-point-restore-metadata \
--backup-vault-name app-vault \
--recovery-point-arn <recovery-point-arn>The response contains a RestoreMetadata map. For an EBS volume it looks like this:
{
"availabilityZone": "us-east-1a",
"encrypted": "true",
"iops": "3000",
"size": "8",
"volumeType": "gp3"
}Save the map to restore-metadata.json and edit it for the new resource. You can change the Availability Zone, for example, to restore into a different zone. Values in the map are strings, even when they look like numbers. Keys differ by resource type and can change as services add features, so always start from the metadata AWS Backup returns, not from a template you wrote earlier.
Step 3: start the restore job
aws backup start-restore-job \
--recovery-point-arn <recovery-point-arn> \
--iam-role-arn arn:aws:iam::123456789012:role/service-role/AWSBackupDefaultServiceRole \
--metadata file://restore-metadata.json \
--resource-type EBS \
--copy-source-tags-to-restored-resourceThe command returns a RestoreJobId. A few details matter here:
- The role must allow restore actions. The managed policy
AWSBackupServiceRolePolicyForRestoresprovides them. The default service role has it attached, but a custom role may only have the backup policy. - If the recovery point is encrypted, the role needs permission to use the KMS key. Otherwise the job fails with an access error.
--copy-source-tags-to-restored-resourcecopies the original resource's tags to the new one. Without it, the restored resource has no tags, so it may fall outside your tag-based backup selections and cost allocation.
Step 4: wait for completion
Poll the job until it leaves PENDING and RUNNING.
JOB_ID=<restore-job-id>
while true; do
STATUS=$(aws backup describe-restore-job \
--restore-job-id "$JOB_ID" \
--query 'Status' --output text)
echo "Status: $STATUS"
case "$STATUS" in
COMPLETED|FAILED|ABORTED) break ;;
esac
sleep 30
done
aws backup describe-restore-job \
--restore-job-id "$JOB_ID" \
--query '[Status,StatusMessage,PercentDone,CreatedResourceArn]'| Status | Meaning | What to do |
|---|---|---|
| `PENDING` | The job is queued. | Wait. |
| `RUNNING` | Data is being restored. | Wait. Check `PercentDone`. |
| `COMPLETED` | The new resource exists. | Verify it. |
| `FAILED` | The restore did not finish. | Read `StatusMessage`. |
| `ABORTED` | The job was stopped. | Start a new job. |
Restore time depends on the resource type and size. An EBS volume restored from a snapshot is available quickly, but blocks load from the snapshot lazily. The first reads can be slower until the data has been fetched.
Step 5: verify the result
COMPLETED only tells you that AWS Backup created the resource. It does not tell you that the data is correct. Verify in two layers.
Layer 1: the resource exists and is configured as expected.
aws ec2 describe-volumes \
--volume-ids <volume-id-from-CreatedResourceArn> \
--query 'Volumes[0].[State,Size,VolumeType,Encrypted,AvailabilityZone]'Check that the state is available and that the size, type, and encryption match what you intended.
Layer 2: the data is usable. Attach the volume to a test instance in the same Availability Zone, mount it read-only, and check the contents:
aws ec2 attach-volume \
--volume-id <volume-id> \
--instance-id <test-instance-id> \
--device /dev/sdf
sudo mkdir -p /mnt/restore-check
sudo mount -o ro /dev/sdf /mnt/restore-check
ls /mnt/restore-check
sha256sum /mnt/restore-check/<known-file>On Nitro-based instances the device may appear under a different name, such as /dev/nvme1n1. Run lsblk to find it. Compare the checksum with a value you recorded earlier. For a database, restore it, connect, and run a query that checks row counts or the latest known transaction.
Differences by resource type
Restores are not uniform across services. The points below cause the most surprises.
- EC2 restores create a new instance from an AMI and its volumes. You choose the instance type, subnet, and security groups in the metadata.
- RDS and Aurora restores create a new instance or cluster with a new endpoint. Applications must be repointed or the identifiers swapped.
- DynamoDB restores create a new table. Settings such as autoscaling and TTL may need to be reapplied.
- EFS restores can target a whole file system, or one file or directory, by setting an item path in the metadata. The restored data lands in a new directory in the target file system.
- Continuous backups let you restore to a chosen second inside the retention window, instead of a discrete recovery point. That feature is covered in a later chapter.
Common errors
- Access denied on the KMS key. The restore role is not allowed to use the key that encrypted the backup. Add the key permissions to the role or the key policy.
- Missing or wrong metadata. The job fails because a required key, such as a subnet group, is absent. Start from
get-recovery-point-restore-metadata. - Restoring from cold storage. The restore works, but takes longer and costs more. Cold storage has a minimum retention of 90 days, so plan accordingly.
- Wrong Region. Recovery points are Regional. To restore in another Region, restore from a cross-Region copy and run the job there.
- Treating
COMPLETEDas proof. Always run the data checks from Step 5.
Exercise
A restore job for an encrypted EBS volume shows status FAILED. The StatusMessage mentions that access to the KMS key was denied. Which two things might you check, and why is a COMPLETED status alone not enough to declare a restore successful?
Show answer
Check that the IAM role passed with --iam-role-arn is allowed to use the KMS key (in its own policy or in the key policy), and that the role has restore permissions such as AWSBackupServiceRolePolicyForRestores. COMPLETED only means AWS Backup created the new resource. You still have to confirm that its configuration is correct and that the data is intact, for example by mounting a restored volume read-only and comparing a known file's checksum.