Created
June 4, 2014 09:31
-
-
Save i97506051502/9ab577d051bff528de23 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 | |
# | |
# make read replica | |
# | |
aws elasticache create-cache-cluster --cache-cluster-id ${REP_CACHE_CLUSTER_ID} --replication-group-id ${REP_GROUP_ID} | |
# wait 15 minutes for creating read replica | |
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 | tr -d '\r'` | |
# | |
# promote from read replica to primary | |
# | |
if [ "${REP_STATUS}" = "0" ]; | |
then | |
aws elasticache modify-replication-group --replication-group-id ${REP_GROUP_ID} --primary-cluster-id ${REP_CACHE_CLUSTER_ID} --apply-immediately | |
break | |
fi | |
done | |
# wait 1 minute for changing status of cache node primary <-> read replica | |
sleep 60 | |
# | |
# delete read replica | |
# | |
while true | |
do | |
RG_STATUS=`aws elasticache describe-replication-groups --replication-group-id ec-test-rg | grep replica | cut -d ':' -f 2 | sed 's/[^"]*"\([^"]*\)"[^"]*/\1/g'` | |
if [ "${RG_STATUS}" = "replica" ]; | |
then | |
aws elasticache delete-cache-cluster --cache-cluster-id ${PRI_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