This topic explains how to archive data from MySQL or PostgreSQL databases to an ApsaraDB RDS for MySQL instance.
Data archiving is currently in public preview.
Supported databases for archiving to ApsaraDB RDS for MySQL
-
MySQL databases: ApsaraDB RDS for MySQL, PolarDB for MySQL, AnalyticDB for MySQL 3.0, and PolarDB-X 2.0.
NoteThe account of a MySQL database must have the REPLICATION CLIENT permission.
-
PostgreSQL databases: ApsaraDB RDS for PostgreSQL and PolarDB for PostgreSQL.
Usage notes
-
Each source table must have a primary or unique key.
NoteYour source tables should contain a timestamp field that indicates when the data was last modified. You can use this field as a filter condition for archiving.
-
To automatically clean up source tables after archiving, ensure your source database has sufficient tablespace to prevent archiving failures.
To run periodic archiving tasks, the control mode for both the source and destination databases must be Security Collaboration or Stable Change. For one-time tasks, there is no restriction on the database control mode.
NoteIf the control mode for your instances is Stable Change, enable security protection or change the control mode to Security Collaboration before you run a periodic archiving task. This prevents task failures due to an expired instance logon. For more information, see Enable security protection and Change the control mode of an instance.
Billing
The Data Management (DMS) data archiving feature is free of charge. For information about the billable items of DMS, see Billable items (DMS).
Sample table data
This topic uses the orders_test01 table as an example. The table contains the gmt_modified field, which indicates the last modification time of the business data.
Data archiving
Log in to DMS 5.0.
-
Move the pointer over the
icon in the upper-left corner and choose . NoteIf you use the DMS console in normal mode, choose in the top navigation bar.
-
In the upper-right corner of the page, click Data Archiving.
-
On the new data archiving ticket page, configure the ticket parameters and then click Submit.
This example archives data from one ApsaraDB RDS for MySQL instance to another. Data older than six months from the source table orders_test01 is archived to a database in the destination instance.
Parameter
Required
Description
Task name
Yes
Use a clear and descriptive name for the task.
Archive destination
Yes
Select ApsaraDB RDS for MySQL.
RDS instance
Yes
Search for and select the destination ApsaraDB RDS for MySQL instance.
Source database
Yes
Search for and select the source database.
Archive configuration
Yes
Select the source tables to be archived. You can click Add to add multiple source tables. If you need to archive only specific data, configure filter conditions.
For example, to archive data older than six months, first configure a time variable named
6_month_ago, and then set the filter condition togmt_modified <= '${6_month_ago}'.When configuring the variable, set Time Format to
yyyy-MM-dd. For Time Operation, select -, enter 6, and then select Month.Archive table mapping
No
Maps the source table to a destination table. By default, the destination table has the same name as the source table.
You can click Edit to modify the table name, column information, sharding key, and partition key for the destination table.
Variable configuration
No
You can use configured variables in the filter conditions for archiving. For example, if you create a time variable named
6_month_agowith theyyyy-MM-ddformat and set the offset to -6 months, the variable${6_month_ago}resolves to2021-02-11if the current date is August 12, 2021. For more information about how to configure time variables, see Configure time variables.Post-actions
No
If you select Clean up archived data from source table (delete-lock-free), DMS automatically deletes the archived data from the source table by running a
DELETEstatement as a lock-free change. However, this process creates a temporary backup table in the source database. Ensure your source database has sufficient space to avoid availability issues.To clean up the temporary backup table: After you confirm that the data archiving is complete and the data is correct, you can submit a regular data change ticket to clean up the temporary backup table from the source database.
If you do not select Clean up archived data from source table (delete-lock-free), you must manually delete the data from the source table and optimize the table space after successful archiving.
Clean up source table data: Submit a regular data change ticket to clean up the archived data. For more information, see Regular data change.
Optimize source table space: Submit a lock-free change ticket to optimize the space of the source table. For more information, see Perform lock-free schema changes by using a lock-free change ticket.
Execution mode
Yes
Select an execution mode. The following options are supported:
-
One-time execution: The archiving task runs only once after the ticket is approved.
-
Periodic scheduling: After the ticket is approved, the task runs periodically as configured. For more information, see Periodic scheduling.
-
Approve the ticket.
After the ticket is approved, the system automatically runs the data archiving task. Wait for the task to complete. If the task fails, you can click Details in the Actions column of the execution step to view the task logs. If the task fails due to a transient issue, such as a network or database connection error, you can click Retry Breakpoint to retry it.
NoteThe archived data is stored in the database as tables.
-
Optional: Query the archived data.
Query the archived data
After the data archiving task is successful, go to the Ticket Details page. In the Basic Information section, click View next to Destination Database.
On the SQL Console page, find the destination table in the table list on the left, double-click the table name, and then click Execute to view the archived data.
NoteThe system automatically creates a database and a table in the destination instance with the same names as the source database and table. Therefore, the destination database name is the same as the source database name.
Four new informational columns are added to the archived table without altering the original data.
Archive information (ticket ID and archive time)
Database name
Table name
Instance ID (the ID assigned to the instance by DMS)
FAQ
Q: If I do not specify a destination database when configuring the ticket, where will the source data be archived?
A: DMS automatically creates a destination database with the same name as the source database to store the archived data.