Last active
March 26, 2016 18:25
-
-
Save EthraZa/db9959e5d70f4c02c5a0 to your computer and use it in GitHub Desktop.
Simple ec2-automate-backup runner
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 - | |
### | |
# 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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
aws-missing-tools https://github.com/colinbjohnson/aws-missing-tools