Created
January 20, 2017 20:22
-
-
Save mikejk8s/81e662f4c1f794bf2682aec4e32c0570 to your computer and use it in GitHub Desktop.
gcp autosnapshot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# loop through all disks within this project and create a snapshot | |
gcloud compute disks list --format='value(name,zone)'| while read DISK_NAME ZONE; do | |
gcloud compute disks snapshot $DISK_NAME --snapshot-names gcs-$DISK_NAME-$(date "+%Y-%m-%d-%s") --zone $ZONE | |
done | |
# | |
# snapshots are incremental and dont need to be deleted, deleting snapshots will merge snapshots, so deleting doesn't lose anything | |
# having too many snapshots is unwieldly so this script deletes them after 60 days | |
# | |
gcloud compute snapshots list --filter="creationTimestamp<$(date -d "-2 days" "+%Y-%m-%d")" --regexp "(gcs.*)" --uri | while read SNAPSHOT_URI; do | |
gcloud compute snapshots delete $SNAPSHOT_URI | |
done | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment