I created a snapshot of a VM instance via cloud console. I would like to know how I can restore an instance using a snapshot. The documentation for compute engine is not very helpful. The instance runs on Ubuntu. Thanks.
To restore an instance from a snapshot without deleting/re-creating the instance:
Shut down the instance and detach the boot disk: gcloud beta compute instances detach-disk INSTANCE_NAME --disk BOOT_DISK_NAME
Create a new disk from the snapshot: gcloud compute disks create DISK_NAME --source-snapshot SNAPSHOT_NAME
Attach the disk created from step 2 as the boot disk: gcloud beta compute instances attach-disk INSTANCE_NAME --disk DISK_NAME --boot
Restoring the instance without deleting/re-creating the instance means that after restore, the instance will keep its IP address and other properties like tags, labels, etc.
In Console, you can go to VM Instances from Compute Engine tab.
There you click on '+Create Instance'
and there in section of boot-disk, you can navigate to 'snapshots' tab and select the snapshot you took.
Like this from console, you can Restore your instance.
Let me know, if this doesn't work for you!
Try using:
gcloud compute disks \
create <NEW_INSTANCE_NAME> \
--source-snapshot <SNAPSHOT_NAME> \
--type pd-ssd \
--zone <ZONE>
You could find useful instruction here.
If you want to do it in the web interface, it's pretty easy. Edit your VM instance. Scroll down to your boot disk and click "x" next to the boot volume, then click create button. In the next window give your new volume a meaningful name, set up your snapshot schedule, and then under "source type" select "Snapshot". Choose your snapshot from the dropdown. If you have a customer managed/supplied key (not recommended) select it, otherwise leave it as google-managed key. Click create. Depending on disk size it might take a while. Be patient and let it finish the setup and then start your instance once it is al complete.
Related
I have a GCE ubuntu 18.04 system that overflowed the / partition. Consequently, I can't start a remote shell to fix it. I created a new system from a snapshot, and stopped the old system.
I want to attach the old system disk to the new system, mount it, and delete a bunch of stuff so I can restart it.
However, when I edit the new system disk in the cloud console, the old system disk does not show up as a possible disk to attach. What do I need to do to the old system disk to both preserve it as a system disk, and allow attaching it to the new system?
What do I need to do to the old system disk to both preserve it as a
system disk, and allow attaching it to the new system?
Either the disk is still attached or the new instance is located in a different zone. Follow the steps below.
STEP 1:
Shut down your instance with the disk space problem. Login into the Google Cloud Console. Go to Compute Engine -> VM instances. Click on your instance and make note of the “Boot disk” name. This will be the first disk under “Boot disk and local disks”.
STEP 2:
Create a snapshot of the boot disk before doing anything further. While still in Compute Engine -> Disk. Click on your boot disk. Click on “CREATE SNAPSHOT”.
STEP 3:
Create a new instance in the same zone. A micro instance will work.
STEP 4:
Open a Cloud Shell prompt (this also works from your desktop if gcloud is set up). Execute this command. Replace NAME with your instance name (broken system) and DISK with the boot disk name and ZONE with the zone that the system is in:
gcloud compute instances detach-disk NAME --disk=DISK --zone=ZONE
Make sure that the command did not report an error.
STEP 5:
Now we will attach this disk to the new instance that you created.
Make sure that the repair instance is running before attaching the second disk. Sometimes an instance can get confused on which disk to boot from if more than one disk is bootable.
Go to Compute Engine -> VM instances. Click on your instance. Click Edit. Under “Additional disks” click “Add item”. For name enter/select the disk that you detached from your broken instance. Click Save.
STEP 6:
SSH into your new instance with both disks attached.
STEP 7:
Mount the second disk to the root file system.
Become superuser. Execute sudo -s
Execute df. Make sure that /dev/sdb1 is not mounted.
Create a directory for the mount point: mkdir /mnt/repair
Mount the second disk: mount /dev/sdb1 /mnt/repair
I am trying to migrate a couple of compute engine instances from Europe to Asia.
I need to do this because most of the users for those servers are in Asia and they get faster access to servers in their region. I am trying following command.
gcloud compute instances move asiawindows1 --zone europe-west1-d --destination-zone asia-east1-c
I get following error when I try this
Instances belonging to subnetworks cannot be moved interregionally.
What is the best way to move these servers without manually setting them up in the Asia zone?
Follow steps below in Google Cloud Platform
Create snapshot of your VM instance
Create disk with this snapshot
Create image with disk created
Create a new instance using the image created in steps above and change your zone
The command you are using is for moving across zones of same region and not across regions.
You can create an image of your instance and use the image to create a new instance in different region.
If the auto move is not happening, you can try the manual move of vm instance. First list all the disk to choose the right disk to take snapshot.
gcloud compute disks list
Identify the name of disk from the list and create a snapshot of that one
gcloud compute disks snapshot <disk_name> --snapshot-names <snapshot_disk_name> --zone <current_zone>
Now you can delete your instance in you are trying to move.
gcloud compute instances delete <instance_name> --zone <instance_zone>
Next step is to create a disk from the snapshot you have created in the new zone where you want to create the instance.
gcloud compute disks create <disk_name> --source-snapshot <snapshot_disk_name> --zone <new_zone_name>
Now, you have to create an instance with the disk you have just created mounted on it. Please choose the right machine type for your need, here am going to create an instance with f1-micro.
gcloud compute instances create <instance_name> --machine-type f1-micro --zone <new_zone>
--disk name=<disk_name>,boot=yes,mode=rw
That's it.
Now if you want you can delete the snapshot
gcloud compute snapshots delete <snapshot_name>
GCP Guide says Snapshot the root disk, create an image, and use the image for the new VM root disk.
I am trying to replicate a new instance from my current instance in Google Compute Engine (following Google instruction: https://cloud.google.com/compute/docs/images#create_an_image_from_a_root_persistent_disk).
In step 3 (Terminate your instance), I am following the instruction ($ gcloud compute instances delete example-instance --keep-disks boot). However, it still asks me whether I want to completely delete the instance:
The following instances will be deleted. Attached disks configured to
be auto-deleted will be deleted unless they are attached to any other
instances. Deleting a disk is irreversible and any data on the disk
will be lost. Do you want to continue (Y/n)? n
Am I still able to recover the instance or continue to create the image of my current instance as Google's instruction? If any body has try to replicate Google Compute Engine, please let me know. Thank you!
I just tested this command on my account and deleted my instance using " --keep-disks boot ". This option keeps the boot disk despite the warning message which says "Attached disks configured to be auto-deleted will be deleted....."
You can also use Developers Console, uncheck "Delete boot disk when instance is deleted" under your instance properties and then delete the instance from there.
My free trial period has been cancelled but I would like to continue using my existing engines.
The console says my instance is terminated and is no longer running.
Rebooting the instance gives "The resource .... is not ready' error.
How can I continue using my engines with exact same IP setting and other configurations?
Once an instance is in a 'TERMINATED' state it can no longer be booted. You will need to recreate an instance with the same configuration, IP address and boot disk as you indicate. See this FAQ for more information about the terminated state: https://cloud.google.com/compute/docs/troubleshooting#terminate
To retain your existing IP address you will need to promote it to a static IP address resource. You can then reassign this address resource to your new instance.
$ gcloud compute addresses create address-name --addresses IP_ADDRESS --region REGION
See this article for the exact steps:
https://cloud.google.com/compute/docs/instances-and-network#promote_ephemeral_ip
To migrate the existing data on your disk you could create a snapshot and then restore that snapshot when creating a new instance:
$ gcloud compute disks snapshot DISK
See this article for the detailed steps:
https://cloud.google.com/compute/docs/disks#creating_snapshots
Finally to migrate all the associated configuration and metadata you could use the describe subcommand in the Cloud SDK:
$ gcloud compute instances describe INSTANCE
This would print out the entire configuration for your existing instance which you can then use to recreate in your new instance.
The exact steps are quite similar to the process of migrating an instance from one zone to another. You could essentially follow the guide for that process but recreate your new instance in the same zone if you prefer not to move the location of your data. The steps for migrating an instance across zones can be found here:
https://cloud.google.com/compute/docs/instances#moving_an_instance_between_zones
On Google Compute Engine, is there a way to change the machine type (for example, add cpu cores) after the machine was created?
It is now possible in the Google compute engine (You can refer to this document).
You just need to stop the instance. And you can then edit the instance type and restart.
This seems to be possible in gcloud:
https://cloud.google.com/sdk/gcloud/reference/compute/instances/set-machine-type
gcloud compute instances set-machine-type
allows you to change the machine type of a virtual machine in the TERMINATED state (that is, a virtual machine instance that has been stopped).
For example, if example-instance is a g1-small virtual machine currently in the TERMINATED state, running:
$ gcloud compute instances set-machine-type example-instance \
--zone us-central1-b --machine-type n1-standard-4
will change the machine type to n1-standard-4, so that when you next start example-instance, it will be provisioned as an n1-standard-4 instead of a g1-small.
UPDATE: this answer is no longer true, as the ability to change instance type was added after this answer was written. See accepted answer.
Although there is no direct "edit machine type" option on GCE, the way to achieve that is:
Deleting the old instance (while making sure the disk is not deleted).
Creating a new instance with the desired type and using the disk from the old instance (instead of creating a new one)
Use gcloud compute instances set-machine-type to change a stopped instance to a machine of another type, for example:
$ gcloud compute instances list
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
foobaz us-central1-a f1-micro 10.128.0.2 104.197.19.103 RUNNING
$ gcloud compute instances stop foobaz
$ gcloud compute instances set-machine-type foobaz --machine-type g1-small
$ gcloud compute instances start foobaz
$ gcloud compute instances list
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
foobaz us-central1-a g1-small 10.128.0.2 104.197.179.223 RUNNING
This assumes you've already set your default zone, e.g.:
$ gcloud config set compute/zone us-central1-a
Also, note the EXTERNAL_IP has changed in the example above. If you want to the newly resized machine to keep the original IP address, then before you stop it you should promote the external IP address from ephemeral to static:
$ ipaddr=$(gcloud --format="value(networkInterfaces[0].accessConfigs[0].natIP)" compute instances describe foobaz)
$ gcloud compute addresses create foobaz-ip --addresses $ipaddr
The Google Cloud documentation states that you can do this from the page that lists the VM Instances however it doesn't appear to be that way now. I found that you have to click on the image name in that list. That then brings up a page where you can Edit the instance including the type.
To change the machine type of your VM instance. You need first to stop your VM instance. After that, click edit then change the machine type and then save it.