GCP Restore

How to restore from GCP Snapshots. Let’s say you have an instance called webserver with 2 disks.

Restore from snapshots:

gcloud compute disks create webserver-boot-r \
--project=your-project \
--source-snapshot=webserver-boot-190616 \
--zone=us-central1-a
gcloud compute disks create webserver-data-r \
--project=your-project \
--source-snapshot=webserver-data-190616 \
--zone=us-central1-a

Stop instance. Detach and attach disks:

gcloud compute instances detach-disk webserver --disk=webserver-boot --zone us-central1-a
gcloud compute instances attach-disk webserver --disk=webserver-boot-r --zone us-central1-a --boot
gcloud compute instances detach-disk webserver --disk=webserver-data --zone us-central1-a
gcloud compute instances attach-disk webserver --disk=webserver-data-r --zone us-central1-a

Boot instance.

GCP Attach Detach Disks

Google Cloud Platform just recently released a beta feature called detaching and attaching boot disks. Previously, boot disks were permanently attached to their VM instances. Now you have the ability to detach boot disk from your instance and attach it to another instance without deleting the original instance. You can also replace the boot disks for an instance rather than recreating the entire instance. I’ve tested it on my test account, and it works quite nicely.

I have 2 servers called blue-server and red-server. I’m detaching the disks on blue-server and attaching it to the red-server.

gcloud beta compute instances detach-disk blue-server --disk=blue-server --zone us-central1-c
gcloud beta compute instances attach-disk cyan-server --disk=blue-server --zone us-central1-c
gcloud beta compute instances detach-disk cyan-server --disk=blue-server --zone us-central1-c
gcloud beta compute instances attach-disk blue-server --disk=blue-server --zone us-central1-c

Results:

GCP: Attach and Detach Disks

This new GCP feature is still beta. There might be a few quirks here and there, but overall, it’s a must have feature if you are managing OS.