DTS supports two-way data sync between two databases, which can be applied to multi-site active-active scenarios. In a two-way sync task, two one-way sync tasks are created to establish a two-way topology, and data can be written into both database instances at the same time during sync.
Two-way data sync must follow restrictions on one-way sync and relevant operations. For more information, see the appropriate sync scenario in Databases Supported by Data Sync.
1
, 3
, and 5
are updated in database A, while data records with primary keys 2
, 4
, and 6
are updated in database B). If there are duplicate primary keys in the two source databases for business reasons, select an appropriate conflict resolution policy as instructed in Recommended Configurations for Typical Use Cases to make the sync behavior and data meet the expectations.A two-way sync task consists of two one-way sync tasks to establish a two-way topology. The creation steps for each one-way sync task are similar to those for a general one-way sync task. They differ only in the following sync option settings:
Scenario | Time Requirements | Sync Task | Initialization Type | If Target Already Exists | Conflict Resolution Method | SQL Type |
---|---|---|---|---|---|---|
Scenario 1: Instance A has database/table structures and data, and instance B is empty | Task 2 can be created only after task 1 enters the "incremental sync" phase | Task 1: Forward sync (A < B) | Structure initialization/full data initialization | Precheck and report error | Select an option as needed. | |
Task 2: Reverse sync (B > A) | Do not select | Ignore and execute | ||||
Scenario 2: Instance A has database/table structures and data, and instance B has only database/table structures but no data | None | Task 1: Forward sync (A > B) | Full data initialization | Ignore and execute | ||
Task 2: Reverse sync (B > A) | Do not select | Ignore and execute | ||||
Scenario 3: Both instances A and B have database/table structures and data | None | Task 1: Forward sync (A > B) | Full data initialization | Ignore and execute | ||
Task 2: Reverse sync (B > A) | Full data initialization | Ignore and execute |
This document takes creating two-way sync between self-built MySQL database A in Shanghai region and TencentDB for MySQL database B in Beijing region as an example. Initially, A has database/table structures and data, while B is empty. When a primary key conflict occurs, data updates in A shall prevail. For A > B sync, the primary key conflict resolution policy is Overwrite, and DDL and DML statements are synced. For B > A sync, the policy is Ignore, and only DML statements are synced.
Category | Parameter | Description |
---|---|---|
Task Configuration | Task Name | DTS will automatically generate a task name, which is customizable. |
Running Mode | Immediate execution and scheduled execution are supported. | |
Source Instance Settings | Source Instance Type | The database A type selected during purchase, which cannot be changed. |
Source Instance Region | The database A region selected during purchase, which cannot be changed. | |
Service Provider | Select **Others**. | |
Access Type | For a third-party cloud database, you can select **Public Network** generally or select **VPN Access**, **Direct Connect**, or **CCN** based on your actual network conditions. In this scenario, **Public Network** is selected as an example. For the preparations for different access types, see Overview. | |
Target Instance Settings | Target Instance Type | The target database B type selected during purchase, which cannot be changed. |
Target Instance Region | The target database B region selected during purchase, which cannot be changed. | |
Access Type | In this scenario, select **Database**. | |
Instance ID | Instance ID of database B. | |
Account | Account of database B, which must have the required permissions. | |
Password | Password of database B. |
Category | Parameter | Description |
---|---|---|
Data Initialization Option | Initialization Type | In this scenario, select **Structure initialization/Full data initialization**.
|
If Target Already Exists | In this scenario, select **Precheck and report error**.
| |
Data Sync Option | Conflict Resolution Method | Select a conflict resolution policy based on the business conditions. In this scenario, select **Overwrite**.
|
SQL Type | Supported operations include INSERT, UPDATE, DELETE, and DDL. If you select **Custom DDL**, you can select different DDL statement sync policies as needed. For more information, see Setting SQL Filter Policy. In two-way sync, you can select **DDL** in at most one task. In this scenario, select **DDL** in task 1 but not task 2. | |
Sync Object Option | Database and Table Objects of Source Instance | Select the objects to be synced. |
Selected Object | Database/Table mapping (renaming) is supported. Hover over a database or table name, click the displayed **Edit** icon, and enter a new name in the pop-up window. |
Note:
- If the verification failed, fix the problem as instructed in Database Connection Check and initiate the verification task again.
- If an alarm is displayed in the verification result, it will not affect the task start, but we recommend you click View Details to get the suggestions for adjustment.
The operations of forward and reverse sync tasks are basically the same. The following only describes their differences:
If you no longer need a sync task, you can select More > Stop in the Operation column to stop it.
Was this page helpful?