I am trying to create a backup snapshot of my GCP instance. However, every-time I create a snapshot and boot it up, the /home/ folder contents seem to be missing from my original instance.
Any idea why this is happening and how to fix it?
Could you give more details about the steps that you follow, to create the instance from the snapshot.
In my case I've used this commands and he have my home on the new instance:
gcloud compute --project=your-project-name disks snapshot disk_name_of_your_instance --zone=zone_of_your_instance --snapshot-names=name_of_your_snapshot
gcloud compute --project your-project-name disks create "your-new-instance" --size "10" --zone "us-central1-c" --source-snapshot "name_of_your_snapshot" --type "pd-standard"
gcloud beta compute --project=your-project-name instances create your-new-instance --zone=us-central1-c --machine-type=n1-standard-1 --subnet=your-subnet
Related
I'm currently using windows VM instance in GCP(project1), i want to create same VM with data in my another project(project2)(project in another gmail account). The project2 have access to my project1 which i had setup IAM role.
So what the next step to copy the instance between the project1 to project2 (without loosing the data)?
You can copy a VM instance from one project to another either using a custom image or using disk.
Method 1: Using Custom image
You have to use the following steps to create a mirror VM in another project:
In your source project, create a snapshot of the VM's boot disk, using one of the below command:
$ gcloud compute snapshots create <SNAPSHOT_NAME> --source-disk <SOURCE_DISK> --source-disk-zone <SOURCE_DISK_ZONE>
Create a custom image from the snapshot using the following command:
$ gcloud compute images create <IMAGE_NAME> --source-snapshot=<SOURCE_SNAPSHOT> [--storage-location=<LOCATION>]
In your destination project, create a VM from the custom image using the following command:
$ gcloud compute instances create <VM_NAME> --image-project <IMAGE_PROJECT> [--image <IMAGE> | --image-family <IMAGE_FAMILY>]
Method 2: Using disk
In your source project, create a snapshot of the VM's boot disk, using one of the below command:
$ gcloud compute snapshots create <SNAPSHOT_NAME> --source-disk <SOURCE_DISK> --source-disk-zone <SOURCE_DISK_ZONE>
Then create a disk in the destination project with --source-snapshot:
$ gcloud compute disks create <DISK_NAME> --source-snapshot <SOURCE_SNAPSHOT> --project <destination-project>
Create a VM based on the new disk from step 2
$ gcloud compute instances create <VM_NAME> --project <destination-project> --disk name=<DISK_NAME>,boot=yes
Refer Copying VMs between projects for information.
I'm working my way through GCP ACE material, and when creating a compute instance you can do the following:
gcloud compute instance create --machine-type=f1-micro mylovelyVM
This is all good, but I want to know how to override region and zone in the same command, I know I can just do config set the region and zone but would be nice to know if it's possible in the one line command.
I have tried the following to no avail :
gcloud compute instances create --machine-type=f1-micro mylovelyVM --region us-west2 --zone us-west2-b
gcloud compute instances create --region us-west2 --zone us-west2-b --machine-type=f1-micro mylovelyVM
I have tried variations on this.
I have been using the -h and --help commands to try and work out at what point to specify the region, but so far no luck.
Error message is --region (did you mean '--reservation'?) for every iteration, which leads me to think its not expecting --region flag at that point.
Documentation states the flow should be gcloud <global flags> <service/product> <group/area> <command> <flags> <parameters>
In which case the command should be
gcloud compute --region us-west2 --zone us-west2-b instances create --machine-type=f1-micro mylovelyVM
Is there a limit on chaining overrides or am I doing this wrong?
You create instances in zones not regions. Regions comprise multiple zones and, while some other services are regional, (compute engine) instances must be placed in zones.
So, use only --zone=.. and not --region=...
The documentation is good but gcloud compute instances create has many flags and so it can be confusing:
https://cloud.google.com/sdk/gcloud/reference/compute/instances/create
Using Cloud Console, you can try permutations of the command and, at the bottom, there's an option to have Console show you the equivalent REST or Cloud SDK (gcloud) command. This is helpful.
IMO, it is good practice to specify e.g. --zone, --project and other flags on the command-line rather than use config. It's more typing but it's more explicit and can avoid errors that result from implicit (assumed) values from config.
Best wishes for your learning!
Update
gcloud compute instances create mylovelyvm \
--zone=us-west2-b \
--machine-type=f1-micro \
--project=${PROJECT}
Created [https://www.googleapis.com/compute/v1/projects/${PROJECT}/zones/us-west2-b/instances/mylovelyvm].
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
mylovelyvm us-west2-b f1-micro 10.168.0.2 35.236.23.189 RUNNING
Marking Daz's answer as correct, though I did find a way without specifying project :
gcloud compute instances create my-lovelyVM --zone=us-west2-b --machine-type=f1-micro
Trying to copy some data into a newly created GCP Filestore with the gcloud CLI.
gcloud compute scp --recurse /somedirectore/somefile somefilestore-1:/somemount
gcloud seems unable to find the instance:
ERROR: (gcloud.compute.scp) Could not fetch resource:
- The resource 'projects/k8-spark/zones/us-central1-a/instances/somefilestore-1' was not found
The filestore instance does exist. Wondering if compute scp actually works with filestores? The documentation seems to think so:
https://cloud.google.com/filestore/docs/copying-data
Any help much appreciated!
The error indicates that "somefilestore-1" is not a name for a Compute Engine (GCE) instance, not a Filestore instance. You can find the instance name in Compute Engine [1]. If your instances were created by the Kubernetes Engine, it will likely start with "gke-< your_K8_cluster_name >".
Some section of the documentation refers to GCE instances as "VM instance", note that the Cloud Filestore fileshare is mounted on a Compute Engine Windows VM instance.
[1] https://console.cloud.google.com/compute/instances
How can I create a boot disk type of SSD persistent disk using gcloud?
From the console I can create a VM instance with SSD persistent disk from the image. I am not able to do it using gcloud.
gcloud compute instances create instance1 --image img_name1 --image-project project_id --machine-type=type_value1 --zone=${CONFIG_zone}
By defaults it is creating a Standard Persistent Disk.
You are right, the default disk type for boot disks in new compute engine instances is "Standard persistent disk"
Try to use the optional parameter "--boot-disk-type" for the "gcloud compute instances create" command as described in the gcloud documentation.
With the following command I created a debian test instance with ssd boot disk:
gcloud compute instances create test-vm --machine-type=f1-micro \
--zone=europe-west4-b --boot-disk-type=pd-ssd
You can get the available disk types for each zone via the following gcloud command:
gcloud compute disk-types list
The disk typ "pd-ssd" however seems to be available in all zones.
I am very new to Google Cloud. I was able to setup a wordpress site and am working on it now. However, it appears that my vm instance is using the following asia-east1-a for its zone. I was able to change the Region and Zone using gcloud commands with the following output:
$ gcloud config list compute/region
Your active configuration is: [default]
[compute]
region = us-east4
$ gcloud config list compute/zone
Your active configuration is: [default]
[compute]
zone = us-east4-b
How does one change the active default to the new set zone? I would like my instance to run in the North East Coast of the USA?
Thanks,
T
Use commands below at cloud shell.
To check your preferred region:
$ gcloud compute regions list
To change compute regions, I select us-east4 region:
$ gcloud config set compute/region us-east4
Updated property [compute/region].
$ gcloud config list compute/region
[compute]
region = us-east4
In a similar way, you can change compute/zone.
As described here, project-info metadata can be added per project to specify the default regions and zones. This is used only at the time of initializing gcloud (using gcloud init).
In addition, gcloud supports locally setting the default region and zone using the compute/region and compute/zone configurations (which is what you seem to have added to your local gcloud config). When these properties are set, they will override any configuration set in the project-info.
Since you have set these properties according to your requirements, I think your defaults are set as long as you're using that gcloud configuration.
Do remember that you can always override the zone and region using the --zone and --region arguments to any of the gcloud commands.
Moving instance from one zone to another
Changing the default zone/region does not move any of the existing VMs to a new zone. If you wish to move a VM from one zone to another, you can take a snapshot of the persistent disks, launch a new instance in the desired zone using the snapshot and cleanup the resources used by the original VM.
You can do this using either gcloud or follow a set of steps manually to achieve the same result.
gcloud compute instances move INSTANCE_NAME --zone SOURCE_ZONE --destination-zone DESTINATION_ZONE
In detail, Compute Engine will:
Take snapshots of persistent disks attached to the source instance.
Create copies of the persistent disks in the destination zone.
For instances moving within the same region, temporarily promote any ephemeral external IP addresses assigned to the instance to a static
external IP address.
Create a new instance in the destination zone.
Attach the newly created persistent disks to your new instance.
Assign an external IP address to the new instance. If necessary, demote the address back to an ephemeral external IP address.
Delete the snapshots, original disks, and original instance.
If you want to manually move your instance, you can also perform these
steps by hand.
If you don't remember the specific commands, another option is to change the region and zone in the gcloud configurations file which is located in:
~/.config/gcloud/configurations/config_default
And contain the structure below:
[core]
account = my-account#my-domain
project = my-project
[compute]
zone = asia-south1-a
region = asia-south1
After changing region to us-central-1 you'll get the following output:
gcloud config list compute/region
[compute]
region = us-central1
gcloud config configurations list
NAME IS_ACTIVE ACCOUNT PROJECT COMPUTE_DEFAULT_ZONE COMPUTE_DEFAULT_REGION
default True my-account#my-domain my-project us-central1-a us-central1
Reference to all GCP regions and zones.
Create Image of the existing instance and after create a new instance with a new zone who you like and uploaded this image with you create before
gcloud compute instances move INSTANCE_NAME --destination-zone=DESTINATION_ZONE [--async] [--zone=ZONE] [GCLOUD_WIDE_FLAG …]
gcloud compute instances move facilitates moving a Compute Engine virtual machine from one zone to another.
EXAMPLE :
gcloud compute instances move compute-instance-1 --zone us-central1-b --destination-zone us-central1-f