Skip to content

Instantly share code, notes, and snippets.

@peihsinsu
Created September 19, 2014 13:38
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save peihsinsu/73cb7e28780b137c2bcd to your computer and use it in GitHub Desktop.
Save peihsinsu/73cb7e28780b137c2bcd to your computer and use it in GitHub Desktop.
GCE daily scheduling snapshot backup
#!/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
@peihsinsu
Copy link
Author

Note: Install gcloud and auth first

@bennypowers
Copy link

./gce-snapshot.sh: 16: ./gce-snapshot.sh: Syntax error: "(" unexpected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment