Updated on 2023-03-15 GMT+08:00

Migrating Data Using DRS

Prerequisites

To improve the stability and security of your migration ensure that your instances meet the migration requirements described in Migration Preparations.

Migration Types

  • Full migration

    This migration type is suitable for scenarios where some service interruptions are acceptable. All objects and data in non-system databases are migrated to the destination database in a single batch. The objects include tables, views, and stored procedures. If you perform a full migration, stop operations on the source database, or data generated in the source database during the migration will result in inconsistencies with the destination database.

  • Full+Incremental migration

    This migration type allows you to migrate data without interrupting services. After a full migration initializes the destination database, an incremental migration initiates and parses logs to ensure data consistency between the source and destination databases. If you select the Full+Incremental migration type, data generated during the full migration will be synchronized to the destination database with zero downtime, ensuring that both the source and destination databases remain accessible throughout the process.

Supported Source and Destination Databases

Table 1 Supported databases

Source DB

Destination DB

  • On-premises Mongo (versions 3.2, 3.4, and 4.0)
  • Self-built MongoDB on ECSs (versions 3.2, 3.4, and 4.0)
  • MongoDB 3.2, 3.4, and 4.0 on other clouds (Tencent Cloud MongoDB 3.2 is not supported.)
  • DDS DB instances (versions 3.4 and 4.0)
  • DDS DB instances (versions 3.4, 4.0, and 4.2)
    NOTE:

    The destination database version must be the same as or later than the source database version.

Supported Migration Objects

Different types of migration tasks support different migration objects. For details, see Table 2. DRS will automatically check the objects you selected before the migration.

Table 2 Migration objects

Type

Precautions

Migration objects

  • Object level: table level, database level, or instance level (full migration).
  • Supported migration objects:
    • Associated objects must be migrated at the same time to avoid migration failure caused by missing associated objects. Common associations: collections referenced by views, and views referenced by views
    • Replica set: Only collections (including validator and capped collections), indexes, and views can be migrated.
    • Cluster: Only collections (including validator and capped collections), shard keys, indexes, and views can be migrated.
    • Single node: Only collections (including validator and capped collections), indexes, and views can be migrated.
    • Only user data and source database account information can be migrated. The system databases (for example, local, admin, and config) and system collection cannot be migrated. If service data is stored in a system database, run the renameCollection command to move the service data to the user database.
    • The statement for creating a view cannot contain a regular expression.
    • Collections that contain the _id field without indexes are not supported.
    • The first parameter of BinData() cannot be 2.
    • If ranged sharding is used, maxKey cannot be used as the primary key.
    NOTE:

    The objects that can be migrated have the following constraints:

    • The source database name cannot contain /\."$ or spaces. The collection name and view name cannot start with system. or contain the dollar sign ($).

Database Account Permission Requirements

To start a migration task, the source and destination database users must have permissions listed in the following table. Different types of migration tasks require different permissions. For details, see Table 3. DRS automatically checks the database account permissions in the pre-check phase and provides handling suggestions.

  • You are advised to create an independent database account for DRS task connection to prevent task failures caused by database account password modification.
Table 3 Database account permission

Type

Full migration

Full+Incremental Migration

Source database user

  • Replica set: The source database user must have the readAnyDatabase permission for the admin database.
  • Single node: The source database user must have the readAnyDatabase permission for the admin database.
  • Cluster: The source database user must have the readAnyDatabase permission for the admin database and the read permission for the config database.
  • To migrate accounts and roles of the source database, the source and destination database users must have the read permission for the system.users and system.roles system tables of the admin database.
  • Replica set: The source database user must have the readAnyDatabase permission for the admin database and the read permission for the local database.
  • Single node: The source database user must have the readAnyDatabase permission for the admin database and the read permission for the local database.
  • Cluster: The source mongos node user must have the readAnyDatabase permission for the admin database and the read permission for the config database. The source shard node user must have the readAnyDatabase permission for the admin database and the read permission for the local database.
  • To migrate accounts and roles of the source database, the source and destination database users must have the read permission for the system.users and system.roles system tables of the admin database.

Destination database user

The destination database user must have the dbAdminAnyDatabase permission for the admin database and the readWrite permission for the destination database.

If the destination database is a cluster instance, the database user must have the clusterManager permission for the admin database.

For example, the source database user must have the readAnyDatabase permission for the admin database and the read permission for the config database.

db.grantRolesToUser("Username",[{role:"readAnyDatabase",db:"admin"}, {role:"read",db:"config"}])

Migration Operations

For details, see MongoDB Database Migration in Data Replication Service Best Practices.