AWS EC2 (Elastic Compute Cloud) provides various mechanisms for backup and restore to help you protect your EC2 instances and data from data loss and disasters. In this tutorial we will look into taking backup of an EC2 instance root volume using EC2 snapshots and restoring it back on to the same instance. A root volume in a Linux EC2 instance is the disk that holds the Operating System.
What are EC2 Snapshots?
EC2 Snapshots are point-in-time backups of Amazon Elastic Block Store (EBS) volumes attached to EC2 instances. Snapshots are incremental backups which means only the changes made since the last snapshot are backed up the next time, which makes them cost-effective and efficient. You can utilize snapshots to create new volumes or restore volumes to a previous state. These snapshots are stored in Amazon S3, ensuring high durability.
How EBS Snapshots Work
Amazon Elastic Block Store (EBS) snapshots are block-level backups that capture the state of an EBS volume at a specific point in time. When you create a snapshot, it captures only the blocks that have changed since the last snapshot, making the process efficient and cost-effective. These snapshots are stored in Amazon S3, ensuring high durability.
However, it’s important to note that EBS snapshots are crash-consistent, not application-consistent, meaning they do not save data blocks written after the snapshot initiation if the instance is running. Despite their benefits, EBS snapshots have some limitations, such as lack of scheduling and retention options, inability to create on-premises copies, and the complexity of creating application-consistent snapshots for simplified recovery.
If you’re looking for an AWS EC2 backup solution that provides automated backups with flexible scheduling, retention policies, and the ability to store backups on-premises or in any public cloud, then BDRSuite’s AWS Backup is the perfect choice. BDRSuite offers agentless EC2 instance backups with application-consistent backups, incremental backups, flexible storage options, and flexible recovery, ensuring comprehensive and efficient data protection. Start your 30-day free trial today!
How to create backup snapshot of EC2 instance
In this step-by-step guide, we will use the following resources to test backup and restore.
- EC2 instance: myec2bkptst
- Volume to backup: vol-0120df1950871e695
- EC2 snapshot: myec2snapshot
- EC2 Operating System: Amazon Linux
Let us now begin by creating snapshot for EC2 Instance.
Go to the AWS Management Console, navigate to the EC2 service, select “Volumes” from the left-hand navigation panel, select the EBS volume.
Then, create a snapshot of it. If you already created a snapshot of the EBS volume, you can simply proceed to the restore section below.
The volume attached to the EC2 instance is “myec2bkptst”.
Once the snapshot is created, you can view the snapshot created in the snapshots section.
How to restore EC2 instance from the backup snapshot
Restoring an EC2 volume to a previous state using a snapshot involves creating a new EBS volume from the snapshot and then attaching it to the desired EC2 instance. Below is the step by step instructions on how to restore EC2 instance using a snapshot.
1) Create a New Volume from the Snapshot:
After the snapshot is complete, go to the EC2 service, click on “Snapshots” from the left-hand navigation panel, and find the snapshot you just created. Select the snapshot, click “Actions,” and then choose “Create Volume”
2) Configure the New Volume:
In the “Create Volume” dialog box, you can adjust the size and other settings of the new volume as needed. The availability zone of the new volume should be same as the EC2 instance. The size of the new volume would be same as the original volume size when the snapshot was taken.
The new volume created can be found under the volumes section of EC2 in AWS. Here the volume ID of the new volume is vol-082d3f7b3b586b632.
3) Attach the New Volume to an EC2 Instance:
Once the new volume is created, go to the EC2 service, click on “Volumes” from the left-hand navigation panel, find the newly created volume, and select it.
Click on “Actions,” choose “Attach Volume” and then select the EC2 instance to which you want to attach the volume.
4) Stop the EC2 Instance (if you are restoring root volume):
If the volume you are restoring contains the root volume of the EC2 instance, you’ll need to stop the instance before attaching the new volume.
In this case we are replacing the root volume of EC2 instance. Hence we will shutdown the EC2 instance.
5) Detach the current volume (If you are restoring root volume)
If you are restoring a root volume, detach the current volume that is attached to the EC2 instance. Click on ‘Actions’ and click ‘Detach volume’
Once the volume is detached, you can’t find any instance name in the “Attached Instances” section.
6) Attach new volume from the snapshot to the EC2 Instance:
After stopping the EC2 instance (if required), and detaching the existing volume, attach the new volume to the instance using the “Attach Volume” dialog.
Ensure to use the same device name that was used earlier with the old volume. Else, the instance will not start. In this case, the device name is “/dev/xvda” as it is root volume.
7) Start the EC2 Instance:
Once the volume is attached, start the EC2 instance. The instance will now boot from the restored EBS volume, bringing it back to its previous state at the time the snapshot was taken.
That’s it! Your EC2 instance should now be running with the restored EBS volume from the selected snapshot. Keep in mind that the restoration process will only restore the data on the EBS volume, not any changes made to the instance’s instance store volumes or any other external data sources.
Conclusion:
Backups are critical components of a IT Infrastructure. AWS EC2 snapshots are an easy and quick way to take backups and restore the EC2 instance with ease. Always ensure that you have backups of critical data and test the restore process to ensure you can recover data effectively when needed.
If you’re seeking a robust AWS EC2 backup solution that delivers automated backups with flexible scheduling, retention policies, and the option to store backups on-premises or in any public cloud, BDRSuite’s AWS Backup is the ideal choice. Start your free trial today!
Follow our Twitter and Facebook feeds for new releases, updates, insightful posts and more.