0

Trying to fire off a gcloud snapshot from a cron job on a ubuntu compute-engine. When executed from an ssh session:

gcloud compute disks snapshot disk-1 --zone=us-west1-b --snapshot-names=${snapshot-name}

creates a snapshot with the given name in zone "us-west1-b"

However, the same statement issued from a cron job creates the snapshot in region "us"

Can anyone explain this and how to get the snapshot created in the desired zone?

Not sure if this matters or not, but the vm is in us-west1-b (Oregon), so the cron job executes from that zone. I am in Montana, so probably am considered in us-west3 (Utah) when executing the command from ssh.

0

As per the documentation, a disk snapshot can be created in a Region or a Multi-region. It can't be created in a Zone.

By default the snapshot location is chosen automatically based on the source disk location: it is created in a nearby multi-regional location closest to the region of the source disk. Neither the VM location nor account location affect the default location of the snapshot. gcloud command line parameters --region=REGION and --zone=ZONE define a region and a zone of the source disk, and don't influence the snapshot location too.

In the initial question the snapshot location is not specified. The source disk disk-1 is located in the region us-west1. Therefore its snapshot is created in the default location that is a Multi-region us.

You can specify the snapshot location with the gcloud command line parameter --storage-location=LOCATION that is the Cloud Storage multi-region (us, eu, asia) or the Cloud Storage region (like us-central1, us-east1, europe-west1, asia-west1, etc).

4
  • Thanks, I mis-read the documentation. – Gary Aitken Jun 21 '20 at 1:47
  • ok, now I still don't understand; it complains about the --region and --storage-location arguments: gcloud compute disks snapshot my-disk --region us-west1 --storage-location us-west1 --snapshot-names=snap-01 --csek-key-file=/home/me/keyfile.json produces the errors: unrecognized arguments: --region us-west1 --storage-location us-west1 – Gary Aitken Jun 21 '20 at 2:43
  • apparently the documentation is wrong. It accepts --zone as an argument, but not --region; and it does not accept --storage-location. – Gary Aitken Jun 21 '20 at 4:00
  • If the disk disk-1 was created as Zonal (with the GCP Console option Replicate this disk within region unset), the command gcloud compute disks snapshot needs the --zone parameter to specify the source disk location. – mebius99 Jun 23 '20 at 20:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.