When accidental updates, deletions, or writes corrupt data in your ApsaraDB RDS for MySQL instance, the data tracking feature of Data Management (DMS) lets you pinpoint which rows changed within a specified time window, generate a rollback script from the binary logs, and apply it to restore only the affected rows — without restoring an entire instance or database.
For an overview of all data restoration methods, see Overview of data restoration methods.
Choose a restoration method
Use the following table to decide which restoration method fits your situation before proceeding.
| Method | How it works | Speed | Restorable time range | Cost |
|---|---|---|---|---|
| Data tracking (this guide) | Parses binary logs for a specified time range, generates rollback statements for selected DML operations, and applies them via a data change ticket. | Fast | Flexible Management: last 30 minutes (rollback/rebuild export not available). Stable Change or Security Collaboration: up to 168 hours (log backup disabled) or up to 730 days (log backup enabled). | Flexible Management: free. Stable Change or Security Collaboration: fees apply. |
| Restoration for individual databases and tables | Restores specific databases or tables to a new or existing instance. Restoring to an existing instance triggers a primary/secondary switchover. | Fast (fast mode) or low (standard mode) | Up to 730 days, based on the log backup retention period. | Charged for the new instance and backup storage exceeding the free quota. |
| Full data restoration | Restores all data to a new instance, then migrates it back to the original or another target. | Slow | Up to 730 days, based on the log backup and data backup retention periods. | Charged for the new instance, backup storage exceeding the free quota, and outbound Internet traffic for migration. |
Use data tracking when you need to roll back specific rows from a known time window and want to avoid the overhead of restoring an entire instance.
Prerequisites
Before you begin, ensure that you have:
-
A MySQL 5.6 or later database
-
Binary logging enabled for the database
-
Logged on to the database in DMS (required for Flexible Management and Stable Change modes; not required for Security Collaboration mode)
Limitations
-
Only DML operations (INSERT, UPDATE, DELETE) can be tracked. DDL operations cannot be tracked.
-
Flexible Management mode: tracking is limited to the previous 30 minutes, and rollback or rebuild scripts cannot be exported.
-
Stable Change or Security Collaboration mode: tracking is limited to the binary log retention period.
-
A single data tracking ticket covers a maximum of 48 hours. For longer time ranges, split the range across multiple tickets.
-
If binary logging is disabled or you have not logged on to the database, DMS cannot retrieve binary logs.
Track data changes and generate a rollback script
-
Log on to the DMS console V5.0.
-
In the top navigation bar, click Database Development > Data Tracking > Data Tracking Ticket.
If you use the DMS console in simple mode, move the pointer over the
icon in the upper-left corner and choose All Features > Database Development > Data Tracking > Data Tracking Ticket. -
In the upper-right corner of the Data Tracking Ticket page, click Data Tracking.
-
On the Data Tracking Tickets page, configure the following parameters and click Submit. After you click Submit, DMS automatically retrieves the binary logs. The ticket moves to the Approval step.
Parameter Description Task Name Enter a name that helps you and approvers identify the purpose of the ticket. Database Name Select the database whose data you want to track. You must have management permissions for the database in DMS. Type a prefix to filter the list. Table Name Select one or more tables to track. Track Type Select the operation types to roll back: Insert (generates INSERT rollback statements), Update (generates UPDATE rollback statements), or Delete (generates DELETE rollback statements). Time Range Specify the time window covering the accidental change. Flexible Management mode: limited to the previous 30 minutes. Stable Change or Security Collaboration mode: any range within the binary log retention period, up to 48 hours per ticket. Change Stakeholder Select the stakeholders who need access to ticket details. Only the selected stakeholders and ticket approvers can view the ticket. -
Wait for the ticket to be approved.
By default, the database administrator (DBA) of the selected database approves data tracking tickets. For details about approval rules, see Data tracking.
-
After approval, wait for DMS to download and parse the binary logs.
-
After parsing completes, filter the results by Track Type, Table Name, or Column Name to isolate the rows you want to roll back. Select the target records and click Export Rollback Script. The rollback script is downloaded to your computer.
To review an individual record before exporting, click View Details to see the full row data and copy the rollback statement.
Apply the rollback script
After exporting the rollback script, choose how to apply it based on the number of affected rows:
-
Few affected rows: Run the rollback statements directly in the SQL Console.
-
Many affected rows: Submit a normal data change ticket and upload the exported rollback script as an attachment. DMS applies the SQL statements to the selected database.
API reference
To automate data tracking with the DMS API, use the following operations: