Tag Archives: Amazon EC2

How to Backup and Restore an EC2 Instance

Motivation:

Any changes related to an operating system or an application in an EC2 instance may break its connection. You may try to stop, start, or reboot the instance many times but the problem may still persist. In this case, you may need to restore the instance to a previous stable version.

Viruses, malwares or accidental deletion of data may also require a restore of an instance to a previous stable version.

In order to restore an EC2 instance to a previous version you first need to create its backups either manually or automatically.

Manually backup an EC2 instance:
  1. Click Volumes on the left menu.
  2. Click a volume, click Actions, click Create Snapshot.
Manually restore an EC2 instance:
  1. Click Snapshots on the left menu, click a snapshot of an instance.
  2. Click Actions, click Create Volume.
  3. Let all default settings intact, click Create Volume.
  4. Repeat the first 3 steps for all the snapshots of the instance.
  5. Stop the instance.
  6. Click the instance, click Storage, scroll down and click on the link of /dev/sda1 device.
  7. Click Actions, click Detach Volume (or Force Detach Volume if the Detach Volume function does not work).
  8. Click Volumes on the left menu.
  9. Click on the volume created from the snapshot.
  10. Click Actions, click Attach Volume.
  11. Select the instance, set Device = /dev/sda1, click Attach.

12. Detach and attach the remaining volume to the instance.
13. Start the instance.

Automate backup process for an EC2 instance:
  1. Go to AWS Backup service.
  2. Click Backup plans on the left menu.
  3. Click the Create Backup plan button, select a template (e.g. Daily-35day-Retention), enter a backup plan name (e.g. HuyBien_Backup_Plan).

4. Click Backup plans on the left menu, click on a backup plan name.
5. Scroll down to the Resource assignments section, click the Assign resources button.
6. Enter a resource assignment name (e.g. HuyBien_Instances or HuyBien_Volumes), the scroll down to the Assign resources section.
7. Select Resource ID for Assign by.

8. Select appropriate resources. When you select an EC2 instance, AWS Backup will create backup for all EBS volumes attached to the instance, and then will attach them to an AMI that stores all parameters from the original EC2 instance.
9. Click the Assign resources button.
10. Wait for 1 day, then click on the Backup vaults link on the left menu, click a Backup vault name, scroll down to the Backup section to check for backups of the resources created by the backup plan execution.

Configure backup process time:
  1. Go to https://www.thetimezoneconverter.com/, and convert your time to UTC, for example 1:00 AM Saint Petersburg = 10:00 PM UTC.
  2. Go to AWS Backup, click Backup plans, click on a plan name.
  3. Scroll down to Backup rules, select a rule, click the Edit button.
  4. Scroll down to Backup window, click Customize backup window and enter your times.

 

How to add multiple IPs to an Amazon EC2 virtual machine

Motivation:

You have a Server 2008 R2 machine on Amazon EC2.

You want to secure multiple domains using different  SSL/TLS certificates.

Server 2008 R2 does not support Server Name Indication (SNI). Therefore you need to add multiple IPs to Server 2008 R2 machine to use different SSL/TLS certificates.

Solution:
  1. Create an EC2 virtual machine.
  2. Click on Network Interfaces tab.
  3. Click Create Network Interface button or select an existing network interface and select Actions > Attach.
  4. Click on a network interface ID, click Actions, click Manage IP Addresses, click on the network interface name (beginning with eth…), click the Assign new IP Address button, enter a private IP Address (e.g. 172.30.0.32), click the Save button, click the Confirm button.
  5. Click Elastic IPs tab, click the Allocate Elastic IP address button, click the Allocate button, optionally name the new allocated IP.
  6. Select the new allocated IP, click on Actions , click Associate Address, choose Network interface, then choose a private IP of the network interface with which the elastic IP will be associated, click the Associate button.
  7. Login Windows.
  8. View the network configuration using below command, note the Default Gateway and DNS Servers information.
ipconfig /all

9. Open Control Panel\All Control Panel Items\Network and Sharing Center.

10. Click Change adapter settings link, click a Local Area Network Connection Network.

11. Manually enter one IP address, Default Gateway and DNS Servers information.

12. Click Advance… button to open Advanced TCP/IP Settings screen, and add the private IPs in the 4th step to the machine.

13. Restart the machine.

If you get any issue then try limit the number of private IPs of a network interface to 4 (including the default private IP).