Advertisement
Dooley28

Simple EC2 Snapshot Management

Apr 1st, 2011
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.57 KB | None | 0 0
  1. #Backup all instances
  2. for a in $(ec2-describe-volumes |grep -Ev "ATTACHMENT" |cut -f2);do ec2-create-snapshot $a; done;
  3.  
  4. is_older()
  5. {
  6.   DATE=$(date -d "$1" +%Y-%m-%d)
  7.   TODAY=$(date -d "$(date +%Y-%m-%d) $2 $3 $4 $5" +%s)
  8.   COMPARE=$(date -d "$DATE" +%s)
  9.   test $(($TODAY - $COMPARE)) -le 0 && return 1 || return 0
  10. }
  11.  
  12. #Purge old records
  13. for snapid in $(ec2-describe-snapshots |grep -Ev "ATTACHMENT"| cut -f2 );do
  14.  
  15.   snapdate=$(ec2-describe-snapshots $snapid | cut -f5 | cut -d "T" -f1)
  16.   if is_older $snapdate -7 days ;then
  17.     ec2-delete-snapshot $snapid
  18.   fi
  19. done;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement