{Aurora}RDS PostgreSQL DB スナップショットを Aurora PostgreSQL DB クラスターに移行する

RDS for PostgreSQL スナップショットは、Aurora PostgreSQL と同じかそれ以下のマイナーバージョンを使用する必要があります。

12.6 → 12.6の移行は2021/07/25時点できない模様


-- テスト用 RDS PostgreSQL作成
aws rds describe-db-engine-versions \
--engine postgres \
| jq -c '.DBEngineVersions | [ .Engine, .EngineVersion ]'

aws rds describe-db-engine-versions \
--engine aurora-postgresql \
| jq -c '.DBEngineVersions | [ .Engine, .EngineVersion ]'


aws rds create-db-instance \
--db-instance-identifier postgres01 \
--allocated-storage 20 \
--db-instance-class db.t3.micro \
--engine postgres \
--master-username postgres \
--master-user-password 'password' \
--no-multi-az \
--engine-version 11.4 \
--storage-type gp2 \
--no-publicly-accessible


-- スナップショット作成
aws rds create-db-snapshot \
--db-snapshot-identifier snap01 \
--db-instance-identifier postgres01

-- スナップショットの一覧
aws rds describe-db-snapshots
aws rds describe-db-snapshots | jq -c '.DBSnapshots[] | [ .DBInstanceIdentifier, .DBSnapshotArn ] '


-- Auroraへのスナップショットの移行

aws rds restore-db-cluster-from-snapshot \
--db-cluster-identifier cluster01 \
--snapshot-identifier arn:aws:rds:ap-northeast-1:999999999999:snapshot:snap01 \
--engine aurora-postgresql \
--engine-version 11.4

aws rds create-db-instance \
--db-instance-identifier cluster01-instance01 \
--db-cluster-identifier cluster01 \
--db-instance-class db.t3.medium \
--engine aurora-postgresql

 

-- クリーンアップ

-- RDSインスタンス削除
aws rds delete-db-instance \
--db-instance-identifier postgres01 \
--skip-final-snapshot


-- スナップショット削除
aws rds delete-db-snapshot --db-snapshot-identifier snap01


-- Auroraクラスタ削除

aws rds delete-db-instance \
--db-instance-identifier cluster01-instance01 \
--skip-final-snapshot

aws rds delete-db-cluster \
--db-cluster-identifier cluster01 \
--skip-final-snapshot