简介

场景说明

客户AWS国内有两个DocumentDB数据库(4.0版本),由于成本原因,需要将两个数据库合并成一个数据库,将2个库合并成一个库。因此,需要使用DMS服务,将DocumentDB1--->DocumentDB2,合并成一个DocumentDB数据库。

环境准备

  • AWS Root账户或者IAM账户(IAM用户需具有相关权限)
  • 2个DocumentDB(4.0版本)
  • 1台EC2实例

实践步骤

一、基础环境配置

1、EC2实例上安装Mongo-Shell

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

2、EC2连接DocumentDB

mongo --host admin1.cluster-c2lighgovwg5.docdb.cn-northwest-1.amazonaws.com.cn:27017 --username admin1 --password Test1234

需要修改的参数有host、username和password

3、为数据库中的所有集合启用更改流(最大限度地减少迁移的停机)

db.adminCommand({modifyChangeStreams: 1,
    database: "test",
    collection: "", 
    enable: true});

二、DMS环境

1、DMS复制实例

2、DMS源端点

3、DMS目标端点

创建的目标端点的内容与源端点类似,需要修改的地方,端点类型选择:目标端点

4、测试连接

5、迁移前操作--导索引

安装git
yum install git

下载索引工具
git clone https://github.com/awslabs/amazon-documentdb-tools.git

python3 安装依赖
cd amazon-documentdb-tools/index-tool
pip3 install -r requirements.txt

下载索引数据,源端admin1数据库中必须要有数据库和表,否则下载为空,“.”为当前路径
python3 migrationtools/documentdb_index_tool.py --dump-indexes --host admin1.cluster-c2lighgovwg5.docdb.cn-northwest-1.amazonaws.com.cn --port 27017 --username admin1 --password Test1234 --dir .

导入索引数据
python3 migrationtools/documentdb_index_tool.py --restore-indexes --host admin2.cluster-c2lighgovwg5.docdb.cn-northwest-1.amazonaws.com.cn --port 27017 --username admin2 --password Test1234 --dir ./DB2


下载索引数据和导入索引数据截图如下:

6、检查目标DocumentDB数据库的验证索引是否导入

登录到admin2数据库

查看数据库
show dbs

7、启动数据库迁移任务

创建迁移任务,并且启动/恢复

查看DMS的迁移状态和进度


参考链接

数据库索引工具使用:https://github.com/awslabs/amazon-documentdb-tools/tree/master/index-tool

DocumentDB基础操作:https://blog.csdn.net/weixin_43408020/article/details/116009373

创建复制实例:https://docs.aws.amazon.com/zh_cn/dms/latest/userguide/CHAP_ReplicationInstance.Creating.html

创建源和目标终端节点:https://docs.aws.amazon.com/zh_cn/dms/latest/userguide/CHAP_Endpoints.Creating.html

创建数据库迁移任务:https://docs.aws.amazon.com/zh_cn/dms/latest/userguide/CHAP_Tasks.Creating.html

自我判定

序号

判断描述

自我判定(是否)

1在各搜索引擎中是否能找到知识信息
2是否需要代码集成开发