Last active
August 29, 2015 14:02
-
-
Save i97506051502/923102b32f3523162329 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/sh | |
# | |
# CACHE CLUSTER ID | |
# | |
PRI_CACHE_CLUSTER_ID=ec-test-pri | |
REP_CACHE_CLUSTER_ID=ec-test-rep | |
# | |
# REPLICATION GROUP ID | |
# | |
REP_GROUP_ID=ec-test-rg | |
# | |
# snapshot's name | |
# | |
TODAY=`date +"%Y%m%d"` | |
SNAPSHOT=backup-elasticache-${TODAY} | |
# | |
# make read replica | |
# | |
aws elasticache create-cache-cluster --cache-cluster-id ${REP_CACHE_CLUSTER_ID} --replication-group-id ${REP_GROUP_ID} | |
# wait 15 minutes | |
sleep 900 | |
# | |
# get endpoint of read replica | |
# | |
REP_ENDPOINT=`aws elasticache describe-replication-groups --replication-group-id ${REP_GROUP_ID} | grep Address | grep ${REP_CACHE_CLUSTER_ID} | cut -d ':' -f 2 | sed 's/[^"]*"\([^"]*\)"[^"]*/\1/g'` | |
# | |
# check status of replication | |
# | |
while true | |
do | |
REP_STATUS=`redis-cli -h ${REP_ENDPOINT} info | grep master_sync_in_progress | cut -d ':' -f 2` | |
# | |
# take snapshot | |
# | |
if [ "${REP_STATUS}" = "0" ]; | |
then | |
aws elasticache create-snapshot --cache-cluster-id ${REP_CACHE_CLUSTER_ID} --snapshot-name ${SNAPSHOT} | |
break | |
fi | |
done | |
# | |
# delete read replica | |
# | |
while true | |
do | |
SS_STATUS=`aws elasticache describe-snapshots --snapshot-name backup-elasticache-20140604 --max-records 50 | grep SnapshotStatus | cut -d ':' -f 2 | sed 's/[^"]*"\([^"]*\)"[^"]*/\1/g'` | |
if [ "${SS_STATUS}" = "available" ]; | |
then | |
aws elasticache delete-cache-cluster --cache-cluster-id ${REP_CACHE_CLUSTER_ID} | |
break | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment