Created
September 19, 2014 13:38
-
-
Save peihsinsu/73cb7e28780b137c2bcd to your computer and use it in GitHub Desktop.
GCE daily scheduling snapshot backup
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 | |
# Environments | |
export PATH=/root/google-cloud-sdk/bin:$PATH | |
# Daily create snapshot for "backup_path" listed disks | |
# And remove snapshot 1 week old before | |
# Create snap date | |
export DT=`date +%Y%m%d` | |
# Delete snap date | |
export DT2=`date -d'-1 week' +%Y%m%d` | |
# ex: ( "disk1 asia-east1-b" "disk2 asia-east1-a" ...) | |
backup_path=( "disk-name disk-region" ) | |
for txt in "${backup_path[@]}" | |
do | |
export name=`echo $txt | awk '{print $1}'` | |
export zone=`echo $txt | awk '{print $2}'` | |
gcloud compute disks snapshot $name --snapshot-name snap-$name-v$DT --zone $zone | |
gcloud compute snapshots delete snap-$name-v$DT2 -q | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
./gce-snapshot.sh: 16: ./gce-snapshot.sh: Syntax error: "(" unexpected