This article is linked to the previous article Your Data In the Cloud. This backup strategy is available for both instance root types. It was nevertheless originally designed to backup an instance whose root device was instance-store. If you intend to backup an EBS-backed AMI instance, please note that this process will create an S3-backed AMI that we will convert back to EBS afterwards. The main advantage of this solution is the ability to download your backup.
Creating an S3-backed AMI
This backup is a hot backup : it will create an AMI while your system is still running. To prevent any data inconsistency, at least stop all the main processes which could modify files during the backup process.
- Upload the EC2 AMI Tools to the server you want to backup.
- Make all the scripts available in bin executable :
- Export the required environment variables :
- Bundle your volume to the non-persistent volume by default available on /mnt for all the AWS instances :
- Create a bucket (here nimbleapps) and a folder (here image) in your S3 Volume (AWS Management Console, Tab S3). Upload your image on your S3 storage :
chmod +x =/root/ec2-ami-tools-1.3-56066/bin/*
export PATH=/root/ec2-ami-tools-1.3-56066/bin:$PATH
export EC2_AMITOOL_HOME=/root/ec2-ami-tools-1.3-56066/
export EC2_HOME=/root/ec2-ami-tools-1.3-56066/
ec2-bundle-vol -d /mnt -k private_key.pem -c certificate.pem -u account_number -r i386
Copying / into the image file /mnt/image...
Excluding:
/sys/kernel/debug
/sys/kernel/security
/sys
/proc
/dev/pts
/dev
/dev
/media
/mnt
/proc
/sys
/mnt/image
/mnt/img-mnt
1+0 records in
1+0 records out
1048576 bytes (1.0 MB) copied, 0.0104679 s, 100 MB/s
mke2fs 1.41.11 (14-Mar-2010)
warning: Unable to get device geometry for /mnt/image
Splitting /mnt/image.tar.gz.enc...
Created image.part.00
...
Generating digests for each part...
Digests generated.
Unable to read instance meta-data for ancestor-ami-ids
Unable to read instance meta-data for ramdisk-id
Unable to read instance meta-data for product-codes
Creating bundle manifest...
ec2-bundle-vol complete.
ec2-upload-bundle -b nimbleapps/image -m /mnt/image.manifest.xml -a Access_Key_ID -s Secret_Access_Key
Uploading bundled image parts to the S3 bucket nimbleapps ...
Uploaded image.part.00
...
Uploading manifest ...
Uploaded manifest.
Bundle upload completed.
You should be able to see your image in your S3 bucket : you can now download your OS backup locally via any S3 tool such as S3 browser. You are no longer relying on Amazon to host your OS backup.
Launching an S3-backed instance from the AMI
- Back in the AWS Management console, tab EC2, section AMIs, click the button Register New AMI.
- Enter the link to your image manifest :
- Go to the Instances section and click Launch Instance.
- Click on the MyAMIs tab. Select the AMI created earlier and follow the guidance. Your instance should startup automatically.
http://s3.amazonaws.com:80/bucket_name/folder/image.manifest.xml
Launching an EBS backed instance from the AMI
The problem with the previous process is that it prevents you from having an EBS-backed AMI instance. You can choose to convert your S3-backed AMI to an EBS instance by doing the following :
- Start any EBS-backed AMI instance.
- Upload the ec2-ami-tools in your instance.
- Create an extra EBS volume, attach it to your instance. (Eg. device /dev/sdg)
- Format it. For example :
- Download your S3-backed AMI into the non persistent volume mount in /mnt :
- Unbundle your image like this :
- Dump the unbundled image on the device :
- Mount the volume /dev/sdg (E.g in /media) and delete the following line in the fstab file (E.g /media/etc/fstab) :
- Umount the volume, detach it in AWS Management Console.
- In AWS Management Console, Volume section, right-click on your volume => Create Snapshot From Volume. You can then delete the previous volume.
mkfs.ext3 /dev/sdg
ec2-download-bundle -b nimbleapps/image -a Access_Key_ID -s Secret_Access_Key -k private_key.pem -d /mnt
Downloading manifest image/image.manifest.xml from nimbleapps to /mnt/image.manifest.xml ...
Downloading part image/image.part.00 to /mnt/image.part.00 ...
...
ec2-unbundle -k private_key.pem -m /mnt/image.manifest.xml -s /mnt/ -d /mnt/
Unbundle complete.
dd if=/mnt/image of=/dev/sdg
/dev/sda2 /mnt auto defaults,comment=cloudconfig 0 0
To start the EBS-backed AMI instance from the snapshot :
- Take an EBS-backed AMI instance with a Kernel ID compatible with the one you want to restore.
- Stop this instance, detach the root volume.
- Create a volume from the snapshot.
- Attach this new volume as the root device of your instance.
Conclusion
The EC2 AMI tools allows you:
- to create a backup available for download : you no longer rely on Amazon only to host your backup.
- makes a hot backup which could lead to some inconsistencies.
but it also :
English
Français 