
This assumes you have already configured the aws command line tool. If not, check out my article on Getting Started with the AWS CLI.
There are different ways to go about backing up your Amazon Web Services (AWS) EC2 instances
- Create an Amazon Machine Image (AMI) of your EC2 instance using the AWS CLI (this article)
- Create an Elastic Block Storage (EBS) Volume Snapshot using the AWS CLI
An AMI will be a complete snapshot of the entire EC2 instance, whereas an EBS Volume Snapshot will be a snapshot of one of the EBS Volumes being used by the EC2 instance
By default, when you create a new EC2 instance, the file system being used by the EC2 instance will be an Elastic Block Storage (EBS) Volume. This can be seen on the Storage tab of your EC2 instance.
The aws ec2 describe-volumes command can be used to list your Elastic Block Storage (EBS) Volumes. Notice in this example that the Elastic Block Storage (EBS) Volume has snapshot snap-096dd96dde7d24189.
~]# aws ec2 describe-volumes
[
{
"AvailabilityZone": "us-east-1b",
"Attachments": [
{
"AttachTime": "2023-07-28T19:58:37.000Z",
"InstanceId": "i-0a3ea97aa2383de58",
"VolumeId": "vol-0d989fe3bad4dd2f9",
"State": "attached",
"DeleteOnTermination": true,
"Device": "/dev/xvda"
}
],
"Encrypted": false,
"VolumeType": "gp3",
"VolumeId": "vol-0d989fe3bad4dd2f9",
"State": "in-use",
"Iops": 3000,
"SnapshotId": "snap-096dd96dde7d24189",
"CreateTime": "2023-07-28T19:58:37.544Z",
"MultiAttachEnabled": false,
"Size": 8
}
]
The aws ec2 describe-snapshots can be used to list your Elastic Block Storage (EBS) Volume Snapshots. A snapshot is created when the EBS volume is created, but subsequent snapshots are not automatically created, thus it is your responsibility to create snapshots.
~]# aws ec2 describe-snapshots
[
{
"Description": "",
"Encrypted": false,
"OwnerId": "123456789012",
"Progress": "100%",
"SnapshotId": "snap-096dd96dde7d24189",
"StartTime": "2023-07-25T22:43:53.821000+00:00",
"State": "completed",
"VolumeId": "vol-0d989fe3bad4dd2f9",
"VolumeSize": 8,
"OwnerAlias": "amazon",
"StorageTier": "standard"
}
]
The aws ec2 create-snapshot command can be used to create a snapshot of an Elastic Block Storage (EBS) Volume.
aws ec2 create-snapshot --volume-id vol-0d989fe3bad4dd2f9
The aws ec2 describe-snapshots command should have the new snapshot.
~]$ aws ec2 describe-snapshots --query 'Snapshots[?VolumeId==`vol-0d989fe3bad4dd2f9`]'
[
{
"Description": "",
"Encrypted": false,
"OwnerId": "123456789012",
"Progress": "100%",
"SnapshotId": "snap-09e46801b783ce255",
"StartTime": "2024-04-03T01:49:02.888000+00:00",
"State": "completed",
"VolumeId": "vol-0d989fe3bad4dd2f9",
"VolumeSize": 8,
"StorageTier": "standard"
}
]
Did you find this article helpful?
If so, consider buying me a coffee over at