Skip to content

Instantly share code, notes, and snippets.

@davebeach
Last active November 16, 2016 02:36
Show Gist options
  • Save davebeach/bad89983b56725d2485c575cf6cb90ed to your computer and use it in GitHub Desktop.
Save davebeach/bad89983b56725d2485c575cf6cb90ed to your computer and use it in GitHub Desktop.

Procedure to Recover Instance

Moving Persistent Disk to Another Instance To Regain Access

Procedure for Google Cloud

  • Create a snapshot of your instance’s persistent disk. Using the Google cloud console, create a snapshot of the instance. Console Instructions for Snapshot Example: Instance name is disk-bitnami-drupal-dm-3d36. Name the snapshot - snapshot-1

  • Create a new persistent disk from this snapshot. From the gcloud console for the project execute command:

gcloud compute disks create pro-drupal-disk --source-snapshot=snapshot-1 --type=pd-standard

For SSD change standard to ssd.

  • Create a new instance and attach this disk as an additional disk. To keep things simple, create instance to mirror original. However, this is not required as you can use resize when creating persistent disk below. New instance created pro-drupal-server

Attach the persistent disk from above, to the instance created in this step above.

gcloud compute instances attach-disk pro-drupal-server --disk pro-drupal-disk
  • SSH into your new instance. Using the Google console, go to instance and SSH into server.

  • Find the name of your second disk by running the command ‘ls -l /dev/disk/by-id/’ In the instance pro-drupal-server look for the attached disk with command:

ls -l /dev/disk/by-id/
  • Create a directory to mount the disk (MOUNT_POINT)
sudo mkdir -p /mnt/disks/pro-copy-image
  • Mount the secondary disk using the mount mount tool( /dev/disk/by-id/google-NAME-part1 /MOUNT_POINT’).
sudo mount -o discard,defaults /dev/disk/by-id/google-pro-drupal-disk /mnt/disks/pro-copy-image
  • Change to the mounted directory . Change the security of the new directory
sudo chmod a+w /mnt/disks/pro-copy-image
  • Maintain disk attachment Make entry in /etc/fstab to keep mounted disk after reboot.
echo UUID=`sudo blkid -s UUID -o value /dev/disk/by-id/google-google-pro-drupal-disk' /mnt/disks/pro-copy-image ext4 discard,defaults,nofail 0 2 | sudo tee -a /etc/fstab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment