1

I have created the snapshot schedule policy with label daily,weekly,hourly.But I want an automate way so whenever i create the vm label based policy should be assigned to vm. or

automatically attach my scheduler to vm disks whenver i create new vm and snapshot would save directly to bucket?

Is any one have the automate script for this task??

Thanks in advance !

2 Answers2

0

If you want to attach snapshot schedule policy to all VM's, you can run the below mentioned script:

#!/bin/bash
# loop through all disks within this project  and add snapshot schedule policy to all the VM’s
gcloud compute disks list | tail -n +2 | while read DISK_NAME ZONE c3 c4; do
gcloud compute disks add-resource-policies $DISK_NAME --resource-policies=ss-01 --zone $ZONE
done

However, If you want to automate snapshot schedule and snapshot create operation, you can follow the article here. At this moment, if you want to move the instance boot disk data to Google cloud storage, you can export a boot disk image to Cloud Storage as a tar.gz file that mention here.

kenlukas
  • 3,101
  • 2
  • 16
  • 26
Mahboob
  • 195
  • 6
  • 1
    Thanks mahboob it works for me ! But as i get one more requirement for the same task...can we move this snapshots to storage bucket. ? Is it possible to export the snapshot as i read the google documents i only found to export the images to bucket – manish sawant Sep 19 '19 at 17:29
  • You can export the snapshots to bucket, however, you are not able to export snapshots directly to the gcp bucket. Please follow the below steps to export snapshots to a bucket: 1- create image based on the snapshot 2- create bucket and copy your bucket url then export your image with the following command gcloud alpha compute images export --destination-uri gs://test_buk04/testimage.vmdk --image expo-test-image --export-format vmdk --project yourprojectid – Mahboob Sep 23 '19 at 22:29
0

You can export the snapshots to bucket, however, you are not able to export snapshots directly to the gcp bucket. Please follow the below steps to export snapshots to a bucket:

  1. create image based on the snapshot
  2. create bucket and copy your bucket url then export your image with the following command:
gcloud alpha compute images export --destination-uri gs://test_buk04/testimage.vmdk --image expo-test-image --export-format vmdk --project yourprojectid
RalfFriedl
  • 3,108
  • 4
  • 13
  • 17
Mahboob
  • 195
  • 6