Dooley28

Euca Backup/Purge Snapshots

Apr 26th, 2011
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.01 KB | None | 0 0
  1. #Backup all instances
  2. for region in $(euca-describe-regions |grep -Ev "ATTACHMENT" |cut -f2);do
  3.   export EC2_REGION=$region
  4.   for volid in $(euca-describe-volumes |grep -Ev "ATTACHMENT" |cut -f2);do
  5.     echo "Creating snapshot from $volid in $region";
  6.     euca-create-snapshot $volid
  7.   done;
  8. done;
  9.  
  10. is_older()
  11. {
  12.   DATE=$(date -d "$1" +%Y-%m-%d)
  13.   TODAY=$(date -d "$(date +%Y-%m-%d) $2 $3 $4 $5" +%s)
  14.   COMPARE=$(date -d "$DATE" +%s)
  15.   test $(($TODAY - $COMPARE)) -le 0 && return 1 || return 0
  16. }
  17.  
  18. #Purge old records
  19. for region in $(euca-describe-regions |grep -Ev "ATTACHMENT" |cut -f2);do
  20.   export EC2_REGION=$region
  21.   for snapid in $(euca-describe-snapshots  |grep -Ev "ATTACHMENT"| cut -f2 );do
  22.     snapdate=$(euca-describe-snapshots $snapid | cut -f5 | cut -d "T" -f1)
  23.     echo "Getting snapshot $snapid in $region at $snapdate";
  24.     if is_older $snapdate -7 days ;then
  25.       echo "Purging snapshot $snapid in $region";
  26.       euca-delete-snapshot $snapid
  27.     fi
  28.     sleep 1
  29.   done;
  30. done;
Advertisement
Add Comment
Please, Sign In to add comment