When you change data in a database using the SQL window in DMS, accidental updates, deletions, or writes can cause unexpected results. The data tracking feature in DMS lets you retrieve information about updates that occurred within a specific time period. This period is limited by the retention time of the database's binary logging (binlog). DMS can then generate a rollback script to quickly restore the data to its state before the change.
Prerequisites
The database is MySQL 5.6 or later.
NoteThis includes RDS for MySQL, PolarDB for MySQL, self-managed MySQL databases on ECS instances, self-managed MySQL databases in on-premises data centers, or MySQL databases from other cloud providers that are managed in DMS Enterprise.
Binary logging is enabled for the database.
You have logged on to the target database in DMS.
NoteYou must log on to instances in Flexible Management or Stable Change mode. You do not need to log on to instances in Security Collaboration mode.
Usage notes
For instances in Flexible Management mode, you can track only Data Manipulation Language (DML) operations performed within the last 30 minutes. You cannot export rollback or rebuild scripts.
For instances in Stable Change or Security Collaboration mode, there is no time limit. You can download rollback and rebuild scripts in batches.
The data that DMS can track is limited by the binlog retention period of the target database instance. If the data was changed before this retention period, DMS cannot retrieve it.
If binary logging is not enabled for the database or a logon error occurs, the system cannot retrieve the log files.
The data tracking feature supports tracking only DML data changes, not Data Definition Language (DDL) schema changes.
Procedure
Log in to DMS 5.0.
In the top navigation bar, click .
NoteIf you use the DMS console in simple mode, move the pointer over the
icon in the upper-left corner of the console and choose . In the upper-right corner of the page, click Data Tracking.
On the Data Tracking Ticket Request page, configure the following parameters:
Parameter Name
Description
Task Name
This facilitates future retrieval and provides the approver with a clear operation intent.
Database Name
Specify a database in the instance. You must have permissions to operate the database in DMS. After you enter a prefix of the database name, matching names appear.
Table Name
Search in the specified target tables. You can add multiple tables.
Track Type
Select one or more operation types to search for as needed.
Insert: The rollback statement for an insert is
INSERT.Update: The rollback statement for an update operation is
UPDATE.Delete: The corresponding rollback statement is
DELETE.
Time Range
Select the time range to track.
For instances in Flexible Management mode, you can track data only within a 30-minute range.
For instances in Stable Change and Security Collaboration modes, there is no limit on the time range. However, a single data tracking ticket can track data for a maximum of 48 hours. If the time range exceeds 48 hours, submit multiple tickets for different time segments.
Change Stakeholder
Select stakeholders as needed. Users who are not ticket participants or approvers cannot view the ticket details.
Click Submit. The system retrieves the log files.
The system begins the approval process after retrieving the log file.
Wait for approval.
NoteBy default, the database administrator (DBA) is the approver for data tracking tickets. For more information about the approval rules for data tracking, see Data tracking.
After the ticket is approved, the system downloads and parses the logs.
After the logs are downloaded and parsed, filter the results by dimensions such as Track Type, Table Name, and Column Name to find the rollback script you need to export. Click Export Rollback Script to download the script file to your computer.
NoteClick the View Details button to the right of a target record to view its details and copy the corresponding rollback statement.
The Track Type can be Insert, Update, or Delete.
Related operations
After you export the rollback script, estimate the number of data rows that the rollback SQL statement will affect. Then, choose a method to execute the rollback SQL statement:
If a small number of rows are affected, execute the SQL statement in the SQL window. For more information, see Get started with SQL Console.
If many rows are affected, submit a normal data change ticket. Upload the rollback script as an attachment to the ticket to execute it on the target database. For more information, see Normal data change.
Use APIs to track data.
CreateDataTrackOrder - Creates a data tracking ticket.
GetDataTrackJobDegree - Obtains the progress of a data tracking task.
GetDataTrackJobTableMeta - Obtains the metadata of tables in a data tracking task.
GetDataTrackOrderDetail - Obtains the details of a data tracking ticket.
SearchDataTrackResult - Search the parsing results of data tracking logs
DownloadDataTrackResult - Downloads the parsing results of data tracking logs.
QueryDataTrackResultDownloadStatus - Queries the download progress of the parsing results of data tracking logs.