LoginSignup
1

More than 5 years have passed since last update.

aws wait で RDS のリストアを自動化

Last updated at Posted at 2018-02-24

Aurora のリストア後にパラメータとかも付け替えないといけないので、できる限り自動化したい。

参考

aws wait help

$ aws rds wait help

NAME
       wait -

DESCRIPTION
       Wait until a particular condition is satisfied.

AVAILABLE COMMANDS
       o db-instance-available

       o db-instance-deleted

       o db-snapshot-completed

スクリプト

restore_aurora.sh
#!/bin/bash

set -u
: $1 $2

COLOR=$1
INSTANCE_CLASS=$2

DB_CLUSTER_IDENTIFIER="test-aurora-cluster-${COLOR}"
DB_INSTANCE_IDENTIFIER="test-aurora-${COLOR}"

DB_CLUSTER_PARAMETER_GROUP_NAME="test-cluster-parameter"
DB_PARAMETER_GROUP_NAME="test-parameter"

# alias 有効にする
shopt -s expand_aliases
alias wait_available="aws rds wait db-instance-available --db-instance-identifier ${DB_INSTANCE_IDENTIFIER}"

aws rds restore-db-cluster-from-snapshot \
--cli-input-json file://restore-db-cluster-from-snapshot.json \
--db-cluster-identifier ${DB_CLUSTER_IDENTIFIER}

aws rds create-db-instance \
--cli-input-json file://create-db-instance.json \
--db-instance-identifier ${DB_INSTANCE_IDENTIFIER} \
--db-cluster-identifier ${DB_CLUSTER_IDENTIFIER} \
--db-instance-class ${INSTANCE_CLASS}
wait_available

aws rds modify-db-cluster \
--db-cluster-identifier ${DB_CLUSTER_IDENTIFIER} \
--db-cluster-parameter-group-name ${DB_CLUSTER_PARAMETER_GROUP_NAME} \
--apply-immediately
# wait_available

aws rds modify-db-instance \
--db-instance-identifie ${DB_INSTANCE_IDENTIFIER} \
--db-parameter-group-name ${DB_PARAMETER_GROUP_NAME} \
--apply-immediately
# wait_available

# Reboot は手動でやる
# aws rds reboot-db-instance \
# --db-instance-identifier ${DB_INSTANCE_IDENTIFIER}
# wait_available

Reboot は自動化できなかった

パラメーター変えたので再起動をする必要がある。
modify-db-cluster, modifi-db-instance--apply-immediately オプションをつけてパラメータグループを変えても DB instance はしばらく avalibale な状態になるため wait を使ってもまたずに進んでしまった。独自に wait を作ってもよいけどそれならこのままでいいか。

追記

aws wait はタイムアウトがあるようです。大きなデータを持った RDS の復元ではエラーになって先に進んでしまう。結局ステータスチェックするスクリプト作らないといけないのか。。。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1