Help Center/ Document Database Service/ User Guide/ Data Restorations/ Restoring Data to a Point in Time/ Restoring a Replica Set Database and Table to a Point in Time
Updated on 2023-03-15 GMT+08:00

Restoring a Replica Set Database and Table to a Point in Time

To ensure data integrity and reduce impact on the original instance performance, the system restores the full and incremental data at the selected time point to a temporary instance, automatically exports the databases and tables to be restored, and then restores the databases and tables to the original instance. The time required depends on the amount of data to be backed up and restored on the instance. Please wait.

Restoring databases and tables will not overwrite data in the instance. You can select databases and tables to be restored.

Precautions

  • Currently, only replica set instances of Community Editions 3.2 and 3.4 support the point-in-time recovery at the database and table level.
  • Before performing the restoration, you need enable the automated backup policy.
  • After a successful restoration, a new table named Original table name_bak_Timestamp is generated in the instance by default. If the table contains an index, the namespace of the index is changed to Original database name.Original table name_bak_Timestamp. You can rename the table later as required.
  • New databases and tables will be generated in the original DB instance. Ensure that sufficient storage space is available.
  • The length of <Database name>.<Table name> cannot exceed 120 characters. The length of <Database name>.<Table name>.<Index name> cannot exceed 128 characters, or the restoration may fail.
  • Ensure that the name of the restored table is different from that of the existing table, or the restoration may fail.
  • If you perform a table-level restoration and the table does not exist at the required point in time, an empty table is automatically created. If you perform a database-level restoration, the missing table is not created.

Procedure

  1. Log in to the management console.
  2. Click in the upper left corner and select a region and a project.
  3. Click in the upper left corner of the page and choose Databases > Document Database Service.
  4. On the Instances page, click the replica set instance.
  5. In the navigation pane on the left, choose Backups & Restorations.
  6. On the Backups & Restorations page, click Restore Database and Table.
  7. In the displayed dialog box, configure parameters as required.

    Table 1 Database information

    Parameter

    Description

    Date

    Date when the automated backup of the DB instance is generated.

    Time Range

    Time range during which the automated backup can be restored.

    Time Point

    The specific point in time when the automated full backup is generated.

    Base Time Range

    Time range during which the database and table can be restored based on the automated full backup.

    Database and Table

    Databases and tables that have been automatically backed up within the base time range are displayed on the left. Select the databases and tables on the left to sync information to the area on the right.

    Time Point

    The point in time within the base time range.

    Custom Database and Table

    You can add custom databases and tables as required.

    • The system database cannot be restored. Therefore, the database name cannot be admin or local.
    • The database name cannot contain spaces and the following special characters: ".\/$
    • The table name cannot contain the dollar sign ($) or "system." in prefix.
    • The length of <Database name>.<Table name> cannot exceed 120 characters. The length of <Database name>.<Table name>.<Index name> cannot exceed 128 characters, or the restoration may fail.
    • Ensure that the name of the restored table is different from that of the existing table. Otherwise, the restoration may fail.
    • After a successful restoration, a new table named Original table name_bak_Timestamp is generated in the instance by default. If the table contains an index, the namespace of the index is changed to Original database name.Original table name_bak_Timestamp. You can rename the table later as required.

    To distinguish the point in time of the custom databases and tables from those synchronized on the right, set the point in time to a different value. The system restores data to the custom databases and tables based on the time configured here.

    Type

    You can restore data to a database or table.

    If you perform a table-level restoration and the table does not exist at the required point in time, an empty table is automatically created. If you perform a database-level restore, data will be restored to the database separately, and the table will not be created.

    Click OK to start the restoration. The data in the new database and table is the same as that in the database and table at the selected time point.

    Figure 1 Selecting database and table

  8. On the Instances page, the DB instance status is Restoring. During the restoration process, services are not interrupted.
  9. After the restoration is successful, manage data in the database and table as required.

    If you need to use the original database and table names, you can use a rename operation to back up the original database and table and switch your service to the restored database and table. Then, delete the original database and table after ensuring that your services are normal.

    Example:

    db.adminCommand({renameCollection: "db1.test1", to: "db2.test2"})

    The above command is used to move the test1 table from the db1 database to the db2 database and rename the table to test2.