Backup process of EC2 instance
Make a backup snapshot using the AWS console (This is a manual process for taking one snapshot)
This is a simple backup procedure for taking one snapshot and storing it in EBS (Elastic Block Store). A snapshot is a copy of a disk volume. A snapshot is not a complete copy – it is only the bits that have changed since the last snapshot.
First find the name of the volume to back up.
- Open the AWS console. (https://console.aws.amazon.com/ec2)
- Navigate to the list of EC2 instances. The breadcrumbs to follow are EC2 tab > INSTANCES > Instances.
- Display the root device name of the instance to back up. Tick the row in the top pane, click the sda1 link in the bottom pane and a popup box appears with the volume’s EBS ID name, along the lines of vol-12345678. Note down the EBS ID.
- Now make a snapshot.
- Open the snapshot dialog box. ELASTIC BLOCK STORE | Snapshots | Create Snapshot button in the top pane.
- Fill in the form. Entered the name as Restore WordPress Prod.
- Click the Create button. The AWS apps behind the scenes create the backup in a couple minutes.
Restore process of EC2 insatnce
Restore a backup snapshot by mounting on an existing EC2 machine
Make a volume from the snapshot to mount the volume on an existing EC2 machine and copy files from it. You can’t mount a volume from one zone on a machine in another zone.
Check the EC2 instance:
- Pick an instance. EC2 tab | INSTANCES | Instances.
- Make a note of the EC2 instance availability zone.
Create a volume:
- Find the snapshot you want to copy files from and tick the box. ELASTIC BLOCK STORE | Snapshots
- Click the Create Volume button and fill in the fields.
- The Size must be bigger than the snapshot size (free micro-instances get an 8GB volume).
- The Availability Zone must be the same as the EC2 insatnce.
- The Snapshot is already selected, more or less like snap12345678
- Click the Yes, Create button. A new line appears in the Volumes table. ELASTIC BLOCK STORE | Volumes
Attach the volume:
- Click the Attach Volume button and fill in the fields.
- The Volume value is already there.
- Pick your insatnce name i-12345678 (running) from the drop-down list of Instances.
- The Devices field shows the first available device name, like /dev/sdf.
- Click the Yes, Create button. A new device magically appears on the EC2 machine.
- Close the AWS console.
Copy files:
- Open the putty and connect to the server.
- Mount the new volume.
sudo mount /dev/sdf /mnt/ - Copy any files you want to the old volume.
cp /mnt/home/ec2-user/var/www/home/ec2-user/var/www
Clean up:
- Unmount the new volume.
sudo umount /mnt/ - Close the putty.