Skip to content

Instantly share code, notes, and snippets.

@EthraZa
Last active March 26, 2016 18:25
Show Gist options
  • Save EthraZa/db9959e5d70f4c02c5a0 to your computer and use it in GitHub Desktop.
Save EthraZa/db9959e5d70f4c02c5a0 to your computer and use it in GitHub Desktop.
Simple ec2-automate-backup runner
#!/bin/bash -
###
# Simple ec2-automate-backup runner
# Author: Allan Brazute
###
# Setup
BKP_DEVICES_PATHS="/var/lib/mongo /var/lib/mysql"
BKP_KEEP_DAYS=7
BKP_VOLUME_TAG="AutoBackup,Values=true"
EC2_AVAIL_ZONE="`/usr/bin/wget -q -O - http://instance-data/latest/meta-data/placement/availability-zone || echo sa-east-1a`"
AWS_DEFAULT_REGION="`echo \"$EC2_AVAIL_ZONE\" | sed -e 's:\([0-9][0-9]*\)[a-z]*\$:\\1:'`"
# Params
FSFREEZE=/sbin/fsfreeze
EC2AUTOBACKUP=/usr/local/sbin/ec2-automate-backup.sh
PRIMER=/etc/aws-missing-tools/cron-primer.sh
LOG=/usr/bin/logger
SCRIPTNAME=$(basename $0)
# Backup routine
$LOG -i -s -t $SCRIPTNAME "ec2-automate-backup[$$]: Script Init"
for P in $BKP_DEVICES_PATHS
do
$LOG -i -s -t $SCRIPTNAME "Freezing $P"
$FSFREEZE --freeze $P
done
sleep 1
$LOG `$EC2AUTOBACKUP -u -r $AWS_DEFAULT_REGION -s tag -t "$BKP_VOLUME_TAG" -k $BKP_KEEP_DAYS -p -n -c $PRIMER`
sleep 1
for P in $BKP_DEVICES_PATHS
do
$FSFREEZE --unfreeze $P
$LOG -i -s -t $SCRIPTNAME "Unfreezing $P"
done
$LOG -i -s -t $SCRIPTNAME "ec2-automate-backup[$$]: Script End"
@EthraZa
Copy link
Author

EthraZa commented Mar 19, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment