{RDS}別の AWS リージョンへの自動バックアップのレプリケーション

バックアップレプリケーションは、暗号化された SQL Server DB インスタンスではサポートされていません。

バックアップレプリケーションは、次のデータベースエンジンを実行する RDS DB インスタンスで使用できます。

PostgreSQL バージョン 9.6 以降
Oracle Database バージョン 12.1.0.2.v10 以降
Microsoft SQL Server バージョン 2012 以降

前提:aws-cli/2.2.24
aws cli version 1の場合、一部コマンドが正しく動作しない

-- 1. aws cli version 2 インストール

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"

unzip awscliv2.zip

sudo ./aws/install

aws --version

 

-- 2. インスタンス作成
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 13.3 \
--storage-type gp2 \
--no-publicly-accessible \
--no-enable-performance-insights \
--no-auto-minor-version-upgrade \
--backup-retention-period 1


-- 3. クロスリージョン自動バックアップの有効化

aws rds start-db-instance-automated-backups-replication \
--region ap-northeast-3 \
--source-db-instance-arn "arn:aws:rds:ap-northeast-1:999999999999:db:postgres01" \
--source-region ap-northeast-1 \
--backup-retention-period 1

 

-- 4. レプリケーションされたバックアップに関する情報の検索

aws rds describe-db-instances \
--db-instance-identifier postgres01

aws rds describe-db-instance-automated-backups \
--db-instance-identifier postgres01

export AWS_DEFAULT_REGION=ap-northeast-3
aws rds describe-db-instance-automated-backups \
--db-instance-automated-backups-arn "arn:aws:rds:ap-northeast-3:999999999999:auto-backup:ab-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
export AWS_DEFAULT_REGION=ap-northeast-1

 

-- 5. レプリケーションされたバックアップから指定された時刻への復元


export AWS_DEFAULT_REGION=ap-northeast-3
aws rds restore-db-instance-to-point-in-time \
--source-db-instance-automated-backups-arn "arn:aws:rds:ap-northeast-3:999999999999:auto-backup:ab-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
--target-db-instance-identifier postgres02 \
--restore-time 2021-07-30T15:07:47.143000Z
export AWS_DEFAULT_REGION=ap-northeast-1

 

-- 6. 自動バックアップレプリケーションの停止

aws rds stop-db-instance-automated-backups-replication \
--region ap-northeast-3 \
--source-db-instance-arn "arn:aws:rds:ap-northeast-1:999999999999:db:postgres01"


-- 7. レプリケーションされたバックアップの削除
export AWS_DEFAULT_REGION=ap-northeast-3
aws rds delete-db-instance-automated-backup \
--db-instance-automated-backups-arn "arn:aws:rds:ap-northeast-3:999999999999:auto-backup:ab-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
export AWS_DEFAULT_REGION=ap-northeast-1


-- 8. クリーンアップ

aws rds delete-db-instance \
--db-instance-identifier postgres01 \
--skip-final-snapshot

aws rds delete-db-instance \
--region ap-northeast-3 \
--db-instance-identifier postgres02 \
--skip-final-snapshot