Terms Of Use

Privacy Policy

Featured snippets are MIT license

Gears & Masters

DevOpsnipp.com © 2020

medium.png

GCP Daily Snapshots

Bash script for listing GCE by labels and creating snapshots
Linux & Windows

6

Votes

PROJECT=

gcloud config set project $PROJECT

date=date +%Y-%m-%d-%H-%M-%S

while IFS=',' read -r name disks zone; do echo "name: $name" echo "zone: $zone"

    IFS=';' read -ra diskArray <<< "$disks"
    for disk in "${diskArray[@]}"; do
        echo "disk: $disk"
        gcloud compute disks snapshot $disk --zone=$zone --snapshot-names $disk-$date --async
    donn
    echo "*******"

for Linux vm disk

done < <(gcloud compute instances list --format="csvno-heading" --filter=labels.os=linux --project $PROJECT)

while IFS=',' read -r name disks zone; do echo "name: $name" echo "zone: $zone"

    IFS=';' read -ra diskArray <<< "$disks"
    for disk in "${diskArray[@]}"; do
        echo "disk: $disk"
        gcloud compute disks snapshot $disk --zone=$zone --guest-flush --snapshot-names $disk-$date --async  
    done    
    echo "*******"

for Linux vm disk

done < <(gcloud compute instances list --format="csvno-heading" --filter=labels.os=windows --project $PROJECT)

Vote Here

You must earn at least 1 vote on your snippets to be allowed to vote