Created
March 5, 2014 18:40
-
-
Save njadhav1/9373720 to your computer and use it in GitHub Desktop.
Check a snapshot details of AWS EBS volume
This file contains 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 | |
######## | |
# Purpose :- When you run create snapshot.sh it take some time to create snapshot | |
# the status of snapshot is pending once it start creating. | |
# So after executing create_snapshot.sh after some time you execute check_snapshot to check final status of snapshot | |
# Provide your Access and Secret Key also check your Region | |
# Bug Report to :- jadhav.nitin941@gmail.com | |
######## | |
export JAVA_HOME=/usr/local/java | |
export EC2_HOME=/usr/bin/ec2 | |
export AWS_ACCESS_KEY=************************************* | |
export AWS_SECRET_KEY=************************************* | |
export EC2_URL=https://ec2.ap-southeast-1.amazonaws.com | |
export PATH=/usr/bin/ec2/bin/:$EC2_HOME:$JAVA_HOME:$PATH:/usr/local/elastic-mapreduce-cli:$AWS_SNS_HOME/bin | |
DATE=$(date +%F) | |
BACKUP_DIR="/data" | |
PROGNAME=$(basename $0) | |
BOX=$(uname -n) | |
LOGDIR="${BACKUP_DIR}/logs/" | |
COMPUTATION_LOGFILE="SNAPSHOT_${DATE}.log" | |
LOGFILE="${PROGNAME}_${DATE}.log" | |
LOCKFILE="/tmp/${PROGNAME}.lock" | |
MAILTO="jadhav.nitin941@gmail.com" | |
LOCK_FILE () | |
{ | |
if [ "$1" = "create" ]; then | |
if [ -f $LOCKFILE ]; then | |
SEND_MAIL "ERROR ::" "Unable to create lock may lock file not removed" | |
exit 0 | |
else | |
touch $LOCKFILE | |
fi | |
fi | |
if [ "$1" = "remove" ]; then | |
rm -fr $LOCKFILE | |
exit 0 | |
fi | |
} | |
SEND_MAIL () | |
{ | |
mail -s "${BOX} :: ${PROGNAME} : $1 $2" -F ${MAILFROM} -t $MAILTO < $LOGDIR/$LOGFILE | |
} | |
LOCK_FILE "create" | |
touch $LOGDIR/$LOGFILE | |
echo "Script started at :- $(date)" 1>> $LOGDIR/$LOGFILE 2>> $LOGDIR/$LOGFILE | |
echo "=================================================================================" 1>> $LOGDIR/$LOGFILE 2>> $LOGDIR/$LOGFILE | |
SNAPSHOT_LIST=$(cat ${LOGDIR}${COMPUTATION_LOGFILE} | grep "^snap" | awk '{print $1}' | sort | uniq ) | |
for SNAP_NAME in ${SNAPSHOT_LIST} | |
do | |
ec2-describe-snapshots ${SNAP_NAME} | awk '{print $2 "/\t" $3 "/\t" $4 "/\t" "/\t" $5}' | tr -d '/' 1>> $LOGDIR/$LOGFILE 2>> $LOGDIR/$LOGFILE | |
if [ $? -ne 0 ];then | |
SEND_MAIL "ERROR ::" "Unable to describe Snapshot ${SNAP_NAME} " | |
fi | |
done | |
echo "=================================================================================" 1>> $LOGDIR/$LOGFILE 2>> $LOGDIR/$LOGFILE | |
echo "Script ended at :- $(date)" 1>> $LOGDIR/$LOGFILE 2>> $LOGDIR/$LOGFILE | |
SEND_MAIL "" "Snapshot creation details " | |
LOCK_FILE "remove" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment