AMIMOTO AMI saves all files in Amazon EBS.
So it is useful to use a backup feature of EBS called “Snapshot” for backing up your server images. Here we describe how to create a snapshot and restore from it.
Creating a Snapshot
Let’s create a snapshot of the EBS Volume.
To make a snapshot, you must find the instance ID of the EC2 instance.
You may visit AWS EC2 Console to display the instance list by selecting “Instances” and find the ID.
After that, select the EC2 Console “Volumes” and make sure the instance ID “Attachment information” is the same as the one you have find the above.
You may check the “Attachment Information” by increasing the width of the web browser on the list at the top.
If you have more than one volume, it would be easy to find the ID.
Once you have selected the volume, click “Create Snapshot” from the “Actions” drop down menu.
Creation status of the snapshot will be able to confirm at “Snapshots” of the EC2 console.
“Status” becomes “completed” after a while, then the snapshot is complete.
This operation can be done even the EC2 instance is running. Please note that the data is as it was at the time creating the snapshot started.
If you make any changes on the server to the snapshot after the start, it will not be saved in the snapshot, so if you want to take a complete snapshot, please perform it only after you have shut down the instance once.
Restoring from a Snapshot
Here we will show you how to restore the volume from a snapshot that was created then.
First, select the snapshot you want to restore the EC2 console from “Snapshots”.
Once you have selected a snapshot, click “Create Volume” from the Actions sub-menu.
At the next screen, you can set the type and size of the EBS volume and the availability zone to which you want to create.
- Type: Select from General Purpose (SSD), Provisioned IOPS (SSD), or Magnetic Volumes (※ 1).
- Size: Set the size of the volume to be created. You cannot make a volume size smaller than the original volume that the snapshot was taken, but it’s possible to increase it. (※ 2)
- Availability Zone: Select the availability zone you would want to create the volume. You need to match the availability zone to the running EC2 instance that you want to restore.
※ 1: Please refer to the following URL for Amazon EBS Volume Types here.
※ 2: If you change the size, you may need to run the resize2fs command with the ssh connection to the instance after startup. Please make sure that the size is changed to run the df command or the like after instance startup.
Next, make sure the volume has been created by selecting the EC2 Console “Volumes”. The volume of “in-use” at “State” is attached to a instance, the volume of “Available” is created but not attached to any instance.
Once you have verified that the volume has been created, stop the instance at “Instances” of EC2 console.
Then detach the volumes that are currently attached. Choose “Volumes” at the EC2 Console.
Take note of the device name that is attached to by looking for a volume that is attached to the EC2 instance currently before detaching.
You can verify this by referring to the volume “Attachment Information”. The display would be like the following:
i-xxxxxxxx: / dev / sda1 (attached)
“/dev/sda1” is the device name that is attached. This must be attached to the same device even when you attach a new volume that you created from the snapshot.
Once you are satisfied with your device, go to “Actions” and click the “Detach Volume” from the sub-menu.
By clicking “Actions”, select “Attach Volume” from the sub-menu where you can select the new volume that you created from the snapshot.
Finally, enter the instance ID which will be attached in the “Instance” field, the device path in the “Device” field, and click “Attach”, then restoring from a snapshot is completed.
Attaching a volume is now complete, so please start the instance as usual.