Video Version: YouTube link
In this article we will explore two AWS solutions to backup & restore an instance:
- EC2 snapshots and AMIs
- AWS Backup (and its drawback)
Why do I need to do an on-demand backup?
It is always a good idea to take a backup of your instance before making any changes like windows updates, drivers updates or any other system update, so you have backup to fall back on if changes don't go as planned.
Solution1: Snapshots and AMIs
This solution creates a snapshot of a root volume. During restore, you create a volume out of the snapshot. Once new volume is created, it get swapped with an existing root volume of the instance. Below are the steps how it works.
Backup
- Go to EC2 service --> In the left pane, select instances
- Select the desired instance --> Click Actions
- From drop-down, click on Image and templates --> create Image
- Enter in Image name
my_instance_image
--> Click Create image - Make note of snapshot id that prompted at the top.
Restore
Create a Volume
- Go to EC2 service --> In the left pane, select instances
- Select the desired instance --> Stop the instance
- In the detail(bottom) pane, switch to Storage
- Make note of Root device details i.e. /dev/sda1 (different for windows)
- In the left pane, click snapshots under Elastic Block store --> Select the snapshot created in the Backup process above
- Click Actions --> Click create volume
-
Verify default options i.e. AZ zone should be same as instance --> Add tag
Name:RestoreVol
- Click create volume
Detach an existing volume
- In EC2 console --> In the left pane, select instances
- Select the desired instance --> Stop the instance
- In the detail(bottom) pane, switch to Storage --> Click root volume (device name = Root device name) under Block devices
- Select volume --> Click Actions & from drop-down, click Detach volume --> click Detach
Attach a new Volume
- In EC2 console --> In the left pane, select volumes
- Select
RestoreVol
volume --> Click Actions - From dropdown, click Attach volume -->Select the instance
- Device name /dev/sda1 --> Click attach volume
The Instance HAS BEEN RESTORED. Start the instance and access as you usually would.
Solution2 : AWS BACKUP
AWS Backup is a convent way to take backups with a couple of clicks and restore the backup to a new machine.
Prerequisite: Backup Vault
Before you could backup an instance using AWS Backup. Backup Vault needs to be in place. Backup Vault is a storage location where resources get backed up
Create Backup Vault
- Go to AWS Backup --> In the left pane, select Backup Vault
- Click Create backup vault at the right --> Enter in Backup Vault name
my_vault
- Select default(aws/backup) Encryption Key --> Add tags if required
- Click Create backup vault
Once the vault is created, on-demand backup of your instance can be taken.
Backup your instance
- Go to AWS Backup --> In the left pane, select Backup Vault
- Select the vault you just created --> Under Recovery points, click on Create on-demand backup
- Select EC2 Resource type and your instance for instance ID
- Backup window, select Create backup now --> Retention period, select
Days
and leave1 day
- Backup Vault, select
my_vault
--> IAM role, Keep Default role selected - Click Create on-demand backup
Restore
- In AWS Backup --> In the left pane, select Protected resources
- Select the instance --> Under Recovery points, select Recovery point ID
- Leave everything default or update the values as desired --> Restore backup
Go to EC2 console, a new restored instance would have been created.
Drawback of this solution:
New instance get created with new instance ID, IP address, interface ID etc. and old instance needs to terminated. In Enterprise environments, this could result in issues as old Instance IP or ID could have been serving other purposes.
To avoid creation of a new instance. Use AWS backup to backup EBS volume of the instance and then detach/attach as suggested in snapshot and AMI backup and restore process.
In addition to on-demand backup, scheduled backups can be enabled for your instances like daily, weekly or monthly and how long you would like to retain them. I'll cover more of those in future articles
Cleanup
If you followed the steps suggested above, please remove all those resource to avoid getting billed for them.
Top comments (0)