The data tracking feature provided by Data Management Service (DMS) helps you quickly locate data changes performed during a specified period of time and generates statements for rolling back the data changes. This topic describes how to use the data tracking feature.
When you manage data in databases, the data may not meet your requirements because of misoperations, such as accidental updates, deletions, and write operations. In this case, you need to quickly restore the data to the previous normal state. Conventional methods of restoring data include instance cloning, instance restoration, database restoration, and table restoration. Both database restoration and table restoration depend on fine-grained backup of databases and tables, which causes high costs and requires you to formulate backup plans.
The data tracking feature provided by DMS helps you quickly locate data changes performed during a specified period of time and generates statements for rolling back the data changes. After target data changes are located, DMS allows you to export a script for rolling back multiple data changes at a time. You can submit a data change ticket to run the rollback script in the target database to restore data.
A MySQL database is available. Currently, the data tracking feature can only be used for MySQL databases.
Make sure that the MySQL database is connected to DMS and managed in the DMS console. Such MySQL databases include ApsaraDB RDS for MySQL instances, user-built databases hosted on ECS instances, user-built databases in on-premises data centers, databases provided by third-party cloud service providers, and user-built databases hosted on third-party cloud servers.
Log on to the DMS console.
In the top navigation bar, choose Data Plans > Data Tracking.
Click Data Tracking in the upper-right corner.
On the Data Track Ticket Application page that appears, set relevant parameters and click Submit. The following table describes the parameters.
Parameter Description Task Name (Required) The name of the task. The name needs to help with locating the ticket and clearly show the intention of this ticket. Database Name (Required) A specific database in the target instance. You need to have the permission to manage the database. Enter a keyword and select a database whose name starts with the keyword from the dynamically matched result. Table Name (Required) The table on which you want to track data operations. Enter a keyword and select a table whose name contains the keyword from the dynamically matched result. You can specify multiple tables. Track Type (Required) The type of data operation you want to track. You can select one or more types as needed.
DELETEstatements will be generated to roll back INSERT operations that are tracked.
UPDATEstatements will be generated to roll back UPDATE operations that are tracked.
INSERTstatements will be generated to roll back DELETE operations that are tracked.
Time Range (Required) The time range in which you want to track data operations. The default time range is the last 2 hours.
You can specify a maximum time range of 6 hours in a single ticket. If the time range in which you want to track data operations exceeds 6 hours, split the time range and submit multiple tickets.
The earliest start time of the time range you can specify is the time point at which binlogs were first stored on the target database server.
Change Stakeholder (Optional) The stakeholder of the ticket. You can specify multiple stakeholders. Only users who are relevant to the ticket, including those who participate in the approval process of the ticket, can view ticket details.
After you submit the ticket, the system automatically retrieves related binlogs. If related binlogs are found, the ticket approval process starts.
By default, data tracking tickets are approved by database administrators (DBAs). For more information about approval rules for data tracking tickets, see Data Tracking.
After the ticket is approved, the system automatically starts to download and parse binlogs.
After the binlogs are parsed, select the change records that you want to roll back and click Export Rollback Script.
You can also perform the following operations:
- Select multiple data change records and export the rollback statements for these records at a time. Each page displays 10 records by default and 200 records at most. You can specify the number of records displayed per page as needed.
- Click View Details to the right of a record name. You can view details of the record and copy the corresponding rollback statement.
- Filter INSERT, UPDATE, and DELETE records by using the Track Type drop-down list.