Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How I can migrate a Persistence Disk from one project to another, in Compute Engine?

I would like to know how I can migrate a Persistence Disk (Google Compute Engine) from one project to another? If it's posible.

like image 588
Elizabeth Avatar asked Mar 02 '14 13:03

Elizabeth


People also ask

Can persistent disk be migrated?

Migrate a zonal persistent disk to a regional persistent disk. To convert your existing zonal persistent disk to a regional persistent disk, create a new regional disk by cloning an existing zonal disk. For more information, see Creating a regional disk clone from a zonal disk.

Can a persistent disk be attached to multiple Google Compute Engine instance?

From Google's documentation: It is possible to attach a persistent disk to more than one instance. However, if you attach a persistent disk to multiple instances, all instances must attach the persistent disk in read-only mode. It is not possible to attach the persistent disk to multiple instances in read-write mode.

How is data transfer by Migrate for compute engine?

Each Migrate for Compute Engine Edge deployment incorporates active-active appliances deployed across two zones. Writes are acknowledged in both zones and asynchronously transferred back to on-prem storage to prevent data loss in the event of an outage.


2 Answers

If you want to copy (non-root) persistent disk, do the steps below:

  1. Go to Google Developer Console and detach <disk-name> disk from the machine.
  2. Use gcloud command-line utility to switch to the old project:
    • gcloud config set project <old-project>
  3. Create an image of the <disk-name> disk:
    • gcloud compute images create <image-name> --source-disk=<disk-name> --source-disk-zone=<zone>
  4. The output of the above command will give you a fully qualified link to the image (in the form https://www.googleapis.com/compute/v1/projects/<project-name>/global/images/<image-name>). Alternatively, run: gcloud compute images list --no-standard-images --uri | grep <image-name> to find the link.
  5. Switch to the new project:
    • gcloud config set project <new-project>
  6. Create a new disk from the image:
    • gcloud compute disks create <new-disk-name> --image=<link-to-the-image> --zone=<zone>
like image 165
tjanez Avatar answered Oct 23 '22 12:10

tjanez


As above Mike Lutz's answer, except gcutil is now deprecated, but the 2nd command can also be done with gcloud compute instance are:

1) create your image from you PD (NB! read first! https://cloud.google.com/compute/docs/images#creating_an_image_from_a_root_persistent_disk)

$ gcloud compute images create [example-image] --source-disk [example-disk] --source-disk-zone ZONE --project="old-project-name"

2) Instantiate the image in the new project (goes without saying but you must have access to both projects)

$ gcloud compute instances create [example-instance-1] --project=[new-project-name] --image="https://www.googleapis.com/compute/v1/projects/[old-project-name]/global/images/[image-name]" --boot-disk-size [XXXGB] --machine-type=[machine-type] --network="default" --zone=[datacenter-zone] 
  • you can see the URL of your image in the Images tab under "Equivalent REST"

For additional instance config options see: https://cloud.google.com/sdk/gcloud/reference/compute/instances/create

like image 43
Amos Folarin Avatar answered Oct 23 '22 13:10

Amos Folarin