Giter VIP home page Giter VIP logo

aws-ebs-snapshot's Introduction

AWS-EBS-Snapshot

AWS-EBS-Snapshot Shell Script

#!/bin/bash
# By: Nikit Swaraj DevOps Foradian Technologies 2016
#

echo "Enter the id of image";

read image_id

root_storage_type=`aws ec2 describe-instance-attribute --instance-id $image_id --attribute blockDeviceMapping | grep EBS | sed '1d' |gawk '{print $1}'`

echo "$root_storage_type"

if [ $root_storage_type = "EBS" ]
    then 
        aws ec2 stop-instances --instance-ids $image_id
        ex_it=`echo $?`
        if [ $ex_it = 0 ]
        then 
            echo "Instance has been stopped"
        else
        echo "Some Problem has been occured"
        fi
else

    echo "The instance can’t be stopped because, the Root volume type of the Instance is of Instance-Storage"

fi
echo "Enter the Volume_id of which you wanna create a snapshot"
    
read volume_id
echo "Enter the description or message for that"
aws ec2 create-snapshot --volume-id $volume_id --description "This is my root volume snapshot."
        ex_it=`echo $?`
        if [ $ex_it = 0 ]
                then
                        echo "Snapshot of the volume have been taken"
                else
                echo "Some Problem has been occurred"
                fi
echo "Enter the size of you wanna give while creating the volume"
read size
aws ec2 create-volume --size $size --region ap-southeast-1 --availability-zone ap-southeast-1b --volume-type gp2
        ex_it=`echo $?`
                if [ $ex_it = 0 ]
                then
                        echo "New volume of size $size have been created"
                else
                echo "Some Problem has been occurred"
                fi

echo "Enter the volume id of which u wanna detach or whose snapshot is taken"
read dettachable_volume_id

aws ec2 detach-volume --volume-id $dettachable_volume_id
         ex_it=`echo $?`
                if [ $ex_it = 0 ]
                then
                        echo "The volume $dettachable_volume_id is detached successfully"
                else
                echo "Some Problem has been occurred"
                fi
echo "Enter the volume id which is to be attached with the instance id and block device name"
echo "Volume id"
read volume_id1
echo "instance id"
read instance_id1
echo "Block device name"
read block_dev_name
aws ec2 attach-volume --volume-id $volume_id1 --instance-id $instance_id1 --device $block_dev_name

         ex_it=`echo $?`
                if [ $ex_it = 0 ]
                then
                        echo "The volume $volume_id1 is attached successfully"
                else
                echo "Some Problem has been occurred"
                fi
echo "Starting the instance"

aws ec2 start-instances --instance-ids $instance_id1
         ex_it=`echo $?`
                if [ $ex_it = 0 ]
                then
                        echo "The instance $instance_id1 is started successfully"
                else
                echo "Some Problem has been occurred"
                fi

aws-ebs-snapshot's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.