VoicePulse Blog

Automate backing up your AWS instances (i.e. volumes) using this utility

#!/bin/bash

# Copyright (c) 2017 Ketan Patel, VoicePulse Inc
# REQUIREMENTS:
# - Intended to run on an Amazon Linux AMI
# - Tested with Amazon Linux AMI 2017.03.1.20170623 x86_64 HVM GP2
# - Requires AWS CLI to be installed and configured
# - Requires mailx client: sudo yum install mailx
#
# RELEASE NOTES:
# 2017-08-04 Version 1.0
# - Discover all volumes in a region
# - Find associated instance information
# - Create a snapshot and tag with a unique run ID
# - Send a summary email of snapshot progress & log file attachment
# - Allow for a dry run
#
# Thanks to the N2WS guide at https://n2ws.com/how-to-guides/automate-amazon-ec2-instance-backup.html for a starting point to creating this utility.
#
# DISCLAIMER OF WARRANTY
# THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

# Check for permissions
if [ `id -u` -ne 0 ]; then
  echo "Please run as root: sudo ./ec2_volume_backup.sh"
  exit 1
fi

# Check for arguments
if [ $# -eq 0 ]; then
  echo "Syntax: sudo ./ec2_volume_backup.sh "
  echo "Example: sudo ./ec2_volume_backup.sh us-east-1"
  exit 1
fi

# Configuration
DRY_RUN=1 # Change to 0 to actually create snapshots
SCRIPT_NAME="EC2 Volume Snapper"
VOLUMES_LIST=/var/log/volumes_info
SNAP_CREATION=/var/log/snap_creation
SNAP_SUMMARY=/var/log/snap_summary

# Initialize variables
DATE=`date +%Y%m%d%H%M%S`
REGION=$1
EMAIL_SUBJECT="${SCRIPT_NAME} ${REGION} ${DATE} DRY_RUN=${DRY_RUN}"
EMAIL_LIST=user@user.net

echo "Snapshots Creation Status" > $SNAP_CREATION
echo "Snapshots Creation Status" > $SNAP_SUMMARY

# Extract list of volumes to a list
aws ec2 describe-volumes --region $REGION --query Volumes[*].[Attachments[0].InstanceId,VolumeId] --output text &> $VOLUMES_LIST

if [ -f $VOLUMES_LIST ]; then

# Creating Snapshot for each volume using for loop
while read VOL_INFO; do
  # Getting the Volume InstanceId and VolumeId into the Separate Variables.
  VOL_INSTANCE=`echo $VOL_INFO | awk '{print $1}'`
  VOL_ID=`echo $VOL_INFO | awk '{print $2}'`

  # Creating the Snapshot of the Volumes with Proper Description.
  DESCRIPTION="${VOL_INSTANCE}_${VOL_ID}_${DATE} Automated backup by ${SCRIPT_NAME}"
  echo "aws ec2 create-snapshot --volume-id $VOL_ID --description "$DESCRIPTION" --region $REGION --query 'SnapshotId' --output text &>> $SNAP_CREATION" &>> $SNAP_CREATION
  if [ $DRY_RUN -eq 0 ]; then
    aws ec2 create-snapshot --volume-id $VOL_ID --description "$DESCRIPTION" --region $REGION --query 'SnapshotId' --output text &>> $SNAP_CREATION
    sleep 3
    SNAP_ID=`aws ec2 describe-snapshots --region $REGION --query Snapshots[*].[SnapshotId] --filters "Name=description,Values=$DESCRIPTION" --output text`
    echo "aws ec2 create-tags --resources $SNAP_ID --tags Key=EC2VolumeSnapperRunID,Value=$DATE --region $REGION &>> $SNAP_CREATION" &>> $SNAP_CREATION
    aws ec2 create-tags --resources $SNAP_ID --tags Key=EC2VolumeSnapperRunID,Value=$DATE --region $REGION &>> $SNAP_CREATION
  else
    echo "** DRY RUN ** NO SNAPSHOT CREATED **"
    echo "** DRY RUN ** NO SNAPSHOT CREATED **" &>> $SNAP_SUMMARY
  fi
  echo $DESCRIPTION
done < $VOLUMES_LIST

aws ec2 describe-snapshots --region $REGION --query Snapshots[*].[SnapshotId,State,Progress,Description] --filters "Name=tag-value,Values=$DATE" --output table &>> $SNAP_SUMMARY

# If no volumes were found
else
echo "No volumes found. Exiting." | mail -s "Snapshots Creation Status" $EMAIL_LIST
exit 1
fi

echo >> $SNAP_CREATION
echo >> $SNAP_CREATION

# Send email
mailx -s "$EMAIL_SUBJECT" -a /var/log/snap_creation $EMAIL_LIST < /var/log/snap_summary

Topics: aws

What is Find Me/Follow Me, and How Can it Help Me Run My Business?

Have you ever missed an important call because you needed to step out of your office for a few minutes? Do you want to take business calls on your cell-phone without giving your number out to customers?  Do you need to be reachable during business hours but left alone depending on the time of day, or during holidays? The "Find Me/Follow Me" feature is a must-have for small business operators who want customers to be able to reach them, transparently, wherever they are, whenever they call. Hosted PBX providers such as VoicePulse, 8x8 and RingCentral make this easy, at low cost, for you.

Topics: pbx hosted pbx new features features

Increasing Customer Satisfaction: Why Your Business Needs An IVR

One of the most important aspects of creating a satisfied customer is making sure that when customers call your business, they can reach the person or information they need quickly. Handling phone calls efficiently can improve customer satisfaction. Let us help you find out why your business needs an IVR.

Topics: pbx hosted pbx ivr voip

What is a PBX? | VoicePulse

Introduction

The acronym, "PBX", is short for private branch exchange.  Knowing the full name doesn't shed much light on the purpose of a PBX -- but don't worry, it's less complicated than it sounds and this post will make everything clear.

Topics: pbx phone service reducing expenses voip

What is Hosted Fax?

Faxes anytime, anywhere, and from any device

Hosted Fax turns your email into a fax machine. Now you can send and receive faxes from anywhere, and from any device, that supports email. It requires no special software, and no complicated setup.

Topics: Blog business fax fax to email hosted fax hosted faxing hosted pbx

Hosted PBX Service for Remote Employees

Supporting remote workers has a history of being one of the more challenging tasks IT professionals are faced with.  Over the years, a variety of solutions have been developed to grant off-site employees with remote access to internal applications, and each method has it's own strengths and drawbacks.  Details aside, however, the overarching goals of each remote-access implementation are the same:  reliability, security, and ease of use & administration.

Topics: Blog cloud pbx hosted pbx remote workers

How to Choose a Business Phone System

There’s a lot to consider when choosing a phone system for your business and, unfortunately, many people wind up locked into a service that isn’t ideal. We wrote this article to help simplify the process of finding a system that will meet all of your business needs now, and as you grow.

Topics: Blog hosted voip smb

Get notified of important calls in HipChat using VoicePulse FIVE

In our last post we showed how to use CallCode to notify your team of important callers. First we looked up the caller ID in Zendesk, then if they had the right tag, we sent an alert to a Slack channel.

Of course not everyone uses Slack - what if you use HipChat instead? No problem!

Topics: Blog CallCode new features

Connect your phones to Zendesk, Salesforce, Slack, Hipchat... or anything else with an API!

In our Introducing CallCode post, we announced that CallCode lets you integrate your phone calls with any service that provides a webhook or API. In this post, we'll look at that a little more in-depth with an example that allows you to query your Zendesk installation to identify high-priority customers and post a message to Slack when they call you.

Topics: Blog CallCode new features