Guest User

Untitled

a guest
Mar 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #!/bin/bash
  2. instance_size=$1
  3. cluster_id="mycoolcluster-xxxx"
  4. primary_node="mycoolcluster-node"
  5. region="us-east-1"
  6. pending_status=""
  7. check_for='"PendingModifiedValues": {},'
  8.  
  9. aws rds modify-db-instance --db-instance-identifier "${primary_node}" --db-instance-class "${instance_size}" --apply-immediately --region "${region}"
  10.  
  11. echo "Checking status for ${primary_node}..."
  12. until [ "${pending_status}" != "" ]; do
  13. pending_status=$(aws rds describe-db-instances --db-instance-identifier "${primary_node}" --region "${region}" --output json | grep "${check_for}")
  14. echo "${primary_node} still pending changes, waiting."
  15. sleep 10
  16. done
  17.  
  18. echo "Failing back to ${primary_node}"
  19. # sometimes it seems pending status is removed but node is not yet ready for failback (likely pending-reboot but not shown in CLI response)
  20. # so if an error occurs, keep trying (there's probably a better way to do this)
  21. while [ $? -ne 0 ]; do
  22. aws rds failover-db-cluster --db-cluster-identifier "${cluster_id}" --target-db-instance-identifier "${primary_node}" --region "${region}"
  23. sleep 5
  24. done
Add Comment
Please, Sign In to add comment