2

I have a new client whose previous developer has left her high & dry with her site on Amazon/EC2. He holds the private key to the instance, and though she has full access to the Amazon control panel (she's paying $300/mo for a site that has like 3 visitors per week) she doesn't have any way to get her content off and move to a new host.

I'm not familiar with AWS and am not sure how to help her. The site's group/file permissions are screwed up on the server so exporting the content/database via her WordPress control panel isn't working.

Any ideas on how to help her? Thanks!

Michelle
  • 123
  • 4
  • 1
    One option: stop the instance, mount the EBS volume (disk) to a new EC2 instance (VM), then copy / export the data as required. You can then re-attach the EBS volume to the original instance and start it to get the site back up. – Tim Oct 25 '18 at 21:22
  • You can also make an AMI from the instance and launch it with a new key. – ceejayoz Oct 25 '18 at 21:38

1 Answers1

4

You've got two options:

  1. Create an Image (AMI, snapshot) of the EC2 instance and create a new instance from that Image.

    • It should set the SSH key to the one you specify, i.e. your new one.
    • Make sure that all the Network and Security settings are the same as on the old instance.
    • You may need to re-assign the Elastic IP from from the old webserver instance to the new one, or update DNS to point to the new IP.
  2. Alternatively modify the root volume from a separate EC2 instance.

    1. Start a new EC2 instance with a SSH key you know.

    2. Stop the webserver instance (don't terminate it).

    3. In the EC2 details look for the Root volume name, it will probably be either /dev/xvda or /dev/sda1. Note it down. Then click on the volume id in the pop-up box when you hover over the Root volume name, e.g. vol-1234abcd1234abcd

    4. In the Volumes screen find the current root volume vol-1234abcd1234abcd and from the menu select Detach volume.

      • Make a Snapshot of the volume, just in case.
    5. Now Attach the same volume to the new EC2 instance that you've got access to.

    6. SSH to the new instance and sudo su - to get root privileges.

    7. Mount the webserver volume, it will probably be /dev/sdf1 or /dev/xvdb1 - check dmesg | tail -n10 to get a hint of what the disk name is.

      [root@ip-... ~] # mount /dev/xvdb1 /mnt
      
    8. Copy the contents of /home/ec2-user/.ssh/authorized_keys to /mnt/home/ec2-user/.ssh/authorized_keys - make sure the file permissions and ownership are still the same as they were!

      [root@ip... #] cat /home/ec2-user/.ssh/authorized_keys > /mnt/home/ec2-user/.ssh/authorized_keys
      
      • At the same time you may want to copy out the contents of your WordPress website and the database files (if the DB is on the same instance).
    9. umount /mnt from the shell and then Detach the volume from the AWS Console.

    10. Now Attach it back as the Root volume to the old webserver instance.

      • Note that the Root volume name won't be in the menu! Simply write what you noted down in step 1 above, e.g. /dev/xvda or /dev/sda1.
    11. Start the instance.

If it goes wrong here is how to restore the root filesystem from a snapshot taken in the step 4 above.

That should do. Hope that helps :)

MLu
  • 23,798
  • 5
  • 54
  • 81