-- 1. Amazon DocumentDB クラスターの作成
aws docdb create-db-cluster \
--db-cluster-identifier cluster01 \
--engine docdb \
--engine-version 4.0.0 \
--port 27017 \
--master-username test \
--master-user-password 'password' \
--no-storage-encrypted \
--no-deletion-protection
aws docdb create-db-instance \
--db-instance-identifier instance01 \
--db-instance-class db.t3.medium \
--engine docdb \
--no-auto-minor-version-upgrade \
--db-cluster-identifier cluster01
aws docdb describe-db-clusters \
--filter Name=engine,Values=docdb
aws docdb describe-db-instances \
--filter Name=engine,Values=docdb
-- 2. テストデータ作成
echo -e "[mongodb-org-4.0] \nname=MongoDB Repository\nbaseurl=https://repo.mongodb.org/yum/amazon/2013.03/mongodb-org/4.0/x86_64/\ngpgcheck=1 \nenabled=1 \ngpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc" | sudo tee /etc/yum.repos.d/mongodb-org-4.0.repo
sudo yum install -y mongodb-org-shell
wget https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem
mongo --ssl --host cluster01.cluster-xxxxxxxxxxxx.ap-northeast-1.docdb.amazonaws.com:27017 --sslCAFile rds-combined-ca-bundle.pem --username test
mongo --ssl --host cluster02.cluster-xxxxxxxxxxxx.ap-northeast-1.docdb.amazonaws.com:27017 --sslCAFile rds-combined-ca-bundle.pem --username test
--コレクション作成とデータ追加
use test
db.tab1.insert({_id:1,col2:"val12",col3:13});
db.tab1.insert({_id:2,col2:"val22",col3:23});
-- db.tab1.insert({_id:3,col2:"val32",col3:33});
db.tab1.find()
show dbs
show collections
-- 3. ポイントインタイムに復元する
aws docdb restore-db-cluster-to-point-in-time \
--db-cluster-identifier cluster02 \
--source-db-cluster-identifier cluster01 \
--restore-to-time 2021-08-25T07:43:05Z
aws docdb create-db-instance \
--db-instance-identifier instance02 \
--db-instance-class db.t3.medium \
--engine docdb \
--no-auto-minor-version-upgrade \
--db-cluster-identifier cluster02
-- 4. クリーンアップ
aws docdb delete-db-instance \
--db-instance-identifier instance01
aws docdb delete-db-instance \
--db-instance-identifier instance02
aws docdb delete-db-cluster \
--db-cluster-identifier cluster01 \
--skip-final-snapshot
aws docdb delete-db-cluster \
--db-cluster-identifier cluster02 \
--skip-final-snapshot