Search code examples
amazon-web-servicesamazon-ec2amazon-ebs

Amazon EC2 with EBS how to backup and restore if volume and mount points change


I have an existing EC2 instance which has 2 EBS volumes attached. Now I want to change the instance and have only one big instance which contains ALL the data (aka "/").

How can I easily change the EBSs and its mount points but keep the data?


Solution

    1. take a snapshot of the old EBS root volume
    2. on the snapshot you've just made to "create volume". Set the size of the volume to be the new size root volume that will include everything
    3. launch a new instance called "resizer"
    4. attach the new volume to "resizer"
    5. find out the device id of the new volume with fdisk -l on "resizer". For example it might be /dev/xdvf
    6. run fdisk on the new volume on "resizer" and issue the following commands

      • d <--deletes partition
      • n <--make new partition
      • 1 <- number
      • <- press return to accept default
      • <- press return to accept default
    7. use resize2fs /dev/xdvf1 to grow the disk partition to use all the space

    8. run fsck on /dev/xdvf1
    9. unattach the new volume from the "resizer"
    10. stop the original server
    11. unattach the old root volume from the original server
    12. attach the new root volume with the same name as the old one to the orignal server
    13. start the original server. The new volume should mount with lots of space
    14. you may need to umount the other EBS volume on the original server and remount it on a different path then use cp -ar to copy the data onto the new root volume