A data acquisition method and apparatus
By receiving and executing snapshot files and incremental operation records, the destination database restores specific data at a specified point in time, solving the problem that full recovery in Redis database cannot meet specific data requirements and achieving efficient instant recovery.
Patent Information
- Application Number
- CN202111290089.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-02
- Publication Date
- 2026-11-27
- Estimated Expiration
- 2041-11-02
AI Technical Summary
Existing Redis databases only support full recovery when performing Point-In-Time Recovery (PITR), which cannot meet users' needs for recovering specific data. Furthermore, existing methods are complex and difficult to achieve real-time recovery.
By receiving snapshot files and incremental operation records from the source database, the destination database, after obtaining the status at a specified point in time, extracts specific data from the full dataset according to the data acquisition requirements, thereby achieving real-time recovery of specific data.
It enables efficient recovery of specific data at a specified point in time from a Redis database without increasing complexity, solving the problem that existing technologies cannot meet the requirement of specific data recovery.
Smart Images

Figure CN114237976B_ABST
Abstract
Description
Technical Field
[0001] This specification relates to one or more embodiments in the field of computer applications, and more particularly to a data acquisition method and apparatus. Background Technology
[0002] A key-value database is a database that stores data using key-value pairs. The key serves as a data identifier, used to identify different values. Some key-value databases have backup and recovery capabilities, such as Remote Dictionary Server (Redis).
[0003] Specifically, the recovery function allows the source Redis to generate snapshot files and incremental operation records. The destination Redis can obtain the database corresponding to the snapshot file of the source Redis, receive and execute the operation commands in the incremental operation records from the snapshot file generation time to the specified time point, obtain the database at the specified time point, and replace the source Redis with the obtained destination Redis, thus completing the point-in-time recovery of the database (PITR).
[0004] In related technologies, PITR generally only supports full PITR, but in some cases, database users have a need to perform PITR only on specific data. Summary of the Invention
[0005] In view of the above, one or more embodiments of this specification provide a data acquisition method and apparatus.
[0006] According to a first aspect of one or more embodiments of this specification, a data acquisition method is proposed for enabling a destination database to acquire specific data from a source database at a specified time point; the method includes: The destination database receives the recovery source and incremental operation records; the recovery source is a snapshot file of the source database, and the incremental operation records are operation commands executed on the source database between the generation time of the snapshot file and the specified time point, wherein the generation time of the recovery source is earlier than the specified time point; Obtain the database corresponding to the recovery source, and after obtaining it, execute the operation command in the incremental operation record to obtain the status of the source database at the specified time point; Determine the data acquisition requirements, which are used to characterize the specific data; Extract data that matches the data acquisition requirements from the full data of the state at the specified time point in the source database to obtain specific data from the source database at the specified time point.
[0007] According to a second aspect of one or more embodiments of this specification, a data recovery method is proposed for recovering a database containing specific data from a source database at a specified point in time; the method includes: The source database and the destination database are determined, wherein the destination database obtains specific data from the source database at a specified time point through the data acquisition method described above; The database management terminal replaces the domain name of the source database in the database interface with the domain name of the destination database.
[0008] According to a third aspect of one or more embodiments of this specification, a data acquisition apparatus is provided, applied to a destination database, for enabling the destination database to acquire specific data from a source database at a specified time point; the apparatus includes: A receiving module is used to receive recovery sources and incremental operation records; the recovery source is a snapshot file of the source database, and the incremental operation record is the operation command executed on the source database between the generation time of the snapshot file and the specified time point, wherein the generation time of the recovery source is earlier than the specified time point; The acquisition module is used to acquire the database corresponding to the recovery source, and after the acquisition is completed, execute the operation command in the incremental operation record to obtain the status of the source database at the specified time point; A determination module is used to determine data acquisition requirements, wherein the data acquisition requirements are used to characterize the specific data; The extraction module is used to extract data that matches the data acquisition requirements from the full data of the state at the specified time point in the source database, thereby obtaining specific data in the source database at the specified time point.
[0009] According to a third aspect of one or more embodiments of this specification, a data recovery apparatus is provided for recovering a database containing specific data from a source database at a specified point in time; the apparatus includes: The database determination module is used to determine the source database and the destination database, wherein the destination database obtains specific data from the source database at a specified time point through the data acquisition method described above; The domain name replacement module is used by the database management end to replace the domain name of the source database in the database interface with the domain name of the destination database.
[0010] According to a fifth aspect of one or more embodiments of this specification, a computer-readable storage medium is provided that stores computer instructions, which, when executed by a processor, implement the data acquisition method or data recovery method described above.
[0011] According to a sixth aspect of one or more embodiments of this specification, an electronic device is provided, comprising: processor; Memory used to store processor-executable instructions; The processor implements the aforementioned data acquisition method or data recovery method by running the executable instructions.
[0012] According to a seventh aspect of one or more embodiments of this specification, a computer program is provided that, when run, implements the data acquisition method or data recovery method described above.
[0013] In one or more embodiments of this specification, the target data segment obtains the state of the source database at a specified time point by receiving the recovery source and incremental operation records. Then, according to the determined data acquisition requirements, it extracts specific data from the obtained state of the source database at the specified time point, thereby enabling the target database to obtain the specific data from the source database at the specified time point. In this way, the immediate recovery of specific data is achieved through a relatively simple method.
[0014] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this specification. Attached Figure Description
[0015] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this specification and, together with the description, serve to explain the principles of this specification.
[0016] Figure 1 This is a flowchart illustrating a data acquisition method according to an exemplary embodiment of this specification.
[0017] Figure 2 This is a flowchart illustrating a data recovery method according to an exemplary embodiment of this specification.
[0018] Figure 3A This is a flowchart illustrating a data recovery method according to a specific embodiment of this specification.
[0019] Figure 3B This is a flowchart illustrating another data recovery method according to a specific embodiment of this specification.
[0020] Figure 3C This is a flowchart illustrating yet another data recovery method according to a specific embodiment of this specification.
[0021] Figure 4 This is a block diagram illustrating a data acquisition apparatus according to an exemplary embodiment of this specification.
[0022] Figure 5 This is a block diagram illustrating a data recovery apparatus according to an exemplary embodiment of this specification.
[0023] Figure 6 This specification is a hardware structure diagram of a computer device containing a data acquisition device or a data recovery device, according to an exemplary embodiment. Detailed Implementation
[0024] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with one or more embodiments of this specification. Rather, they are merely examples of apparatuses and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.
[0025] It should be noted that the steps of the corresponding methods are not necessarily performed in the order shown and described in this specification in other embodiments. In some other embodiments, the methods may include more or fewer steps than described in this specification. Furthermore, a single step described in this specification may be broken down into multiple steps in other embodiments; and multiple steps described in this specification may be combined into a single step in other embodiments.
[0026] In related technologies, for the implementation of PITR (Personalized Interruption Recording) for key-value data like Redis, after receiving a data recovery request from a user, the data recovery component downloads all backup files from the backup file storage address of the source database, extracts the recovery source and incremental operation records (corresponding to the backup files in the data recovery request) required by the destination database, and sends the extracted recovery source and incremental operation records to the destination database. This allows the destination database to obtain the database corresponding to the recovery source and execute the operation commands in the received incremental operation records on that database, thus obtaining the state of the source database at a specified point in time. After the destination database obtains the state of the source database at the specified point in time, the database management terminal replaces the source database with the destination database, thereby completing the PITR.
[0027] For Redis databases, PITR generally only supports full PITR, which means restoring all data from the source database at a specified point in time. However, in some cases, database users need to PITR only specific data. For example, for game developers, keys typically represent different users, and values represent data for different users. If data in certain regions or some data is corrupted, game developers may need to PITR only the specific data.
[0028] To simplify the implementation of PITR for specific data, considering that the data recovery component scans backup files and sends them to the destination database, we consider filtering the data recovery component to send only backup files related to specific data to the destination database. Specifically, when sending snapshot files and incremental operation records, we extract specific key-value pairs from the snapshot files and send these key-value pairs as operation commands to the destination Redis, allowing the destination Redis to execute the commands and obtain the specific key-value pairs. Similarly, we extract operation commands containing specific key-value pairs from the incremental operation records and send them to the destination Redis, enabling the destination Redis to execute the received commands and obtain a database containing only the specific data at the specified point in time.
[0029] However, this method can actually increase complexity in some situations. For example, some operation commands have dependencies. Simply extracting the operation command containing a specific key-value pair may not be enough to recover that key-value pair. It is also necessary to determine the dependencies between the operation commands to obtain the specific data. Determining the dependencies between operation commands is quite complicated, and applying this method may not easily retrieve the specific data. For instance, in the first statement, a value is assigned to key 1; in the second statement, a value is assigned to key 2; and in the third statement, key 3 is assigned the union of the values corresponding to key 1 and key 2. If only key 3 is to be recovered, and not key 1 and key 2, only the third statement will be extracted and sent to the destination Redis. However, the third statement does not contain the values corresponding to key 1 and key 2, so executing only the third statement cannot determine the value corresponding to key 3, and key 3 cannot be recovered. Similar statements handle union, intersection, renaming, and moving operations, etc. To obtain key 3, it is necessary to first determine the dependency relationship between key 1, key 2, and key 3, and then delete key 1 and key 2 after obtaining key 3 from the target database. This will increase the complexity of the algorithm and make the method difficult to implement.
[0030] Furthermore, some operation commands assign values or perform other operations on multiple key-value pairs within a single statement. Some of these key-value pairs are what the user wants to recover, while others are not. If this operation command is extracted, the destination database will not only recover the desired key-value pairs but also some unwanted ones. To recover only the desired key-value pairs, this single statement needs to be split into multiple statements, which increases the overall complexity of the method.
[0031] To reduce the complexity of data recovery, we considered first obtaining the complete data from the source database at a specified point in time, and then filtering the obtained complete data to obtain specific data at the specified point in time. Furthermore, considering that data recovery generally requires the participation of a data recovery component, filtering could be performed by the data recovery component or by the destination database. However, if filtering is performed by the data recovery component, it cannot execute database operation commands, thus preventing real-time recovery. Therefore, we ultimately chose to obtain and filter the complete data from the destination database.
[0032] Based on the above analysis, one or more embodiments of this specification provide a data acquisition method. The target data segment receives the recovery source and incremental operation records to obtain the state of the source database at a specified time point. Then, according to determined data acquisition requirements, specific data is extracted from the obtained state of the source database at the specified time point, thereby enabling the target database to obtain the specific data from the source database at the specified time point. In this way, real-time recovery of specific data is achieved through a relatively simple method. It also solves the problems existing in the methods described above.
[0033] The following section will provide a detailed description of one of the data acquisition methods provided in this manual.
[0034] like Figure 1 As shown, Figure 1 This specification illustrates a data acquisition method according to an exemplary embodiment. The method is used to enable a destination database to acquire specific data from a source database at a specified point in time. The method includes: Step 101: The destination database receives the recovery source and incremental operation records; the recovery source is a snapshot file of the source database, and the incremental operation records are operation commands executed on the source database between the generation time of the snapshot file and the specified time point, wherein the generation time of the recovery source is earlier than the specified time point.
[0035] First, it should be noted that the data recovery mentioned in this manual refers to restoring a database to its state at a specified point in time. The data recovery process requires first obtaining the database from the specified point in time, then replacing the current database with the obtained database to complete the data recovery. Data acquisition refers to the process of obtaining the database from the specified point in time. The data recovery and data acquisition methods described in this manual can be applied to key-value databases such as Redis, which can generate snapshot files and operation records.
[0036] Snapshot files and incremental operation records are two types of database backup files. Snapshot files are backups of the database at a specific point in time; in Redis, they are typically stored as RDB files. Snapshot files are generally generated at preset intervals. Operation records, on the other hand, store the operation commands executed by the database; in Redis, they are typically stored as AOF / BINLOG files. Each executed operation command adds a new record to the operation record. Once the size of an AOF / BINLOG file reaches a preset threshold, the operation commands will continue to be stored in the next AOF / BINLOG file. Each operation command in the operation record includes a timestamp to identify when it was executed. The recovery source and incremental operation records are the received snapshot files and operation records that meet the conditions (the limitations on recovery sources and incremental operation records in step 101).
[0037] The source database mentioned in this manual is the database that needs to be recovered. The destination database is used to store specific data from the source database at a specified point in time during the recovery process. Ultimately, the source database needs to be replaced by the obtained destination database to complete the data recovery. The reason for storing specific data in the destination database instead of performing data recovery directly on the source database is that if data recovery were performed directly on the source database, the database would be unusable during this period, affecting normal user operation. Furthermore, if problems occur during the data recovery process directly on the source database, neither the current database nor the database at the specified point in time will be obtained. Therefore, a destination database, distinct from the source database, is selected to retrieve the specified data.
[0038] Furthermore, both the destination and source databases can be local databases or cloud databases. The source and destination databases are two separate database instances.
[0039] For step 101, the received recovery source and incremental operation records can be sent directly from the source database. In other words, when the source database receives the user's data acquisition request, it first determines the snapshot file generated before the specified time point and closest to the specified time point based on the specified time point and data acquisition requirements contained in the acquisition request. The determined snapshot file is used as the recovery source. Then, the timestamp of each operation record in the operation record is compared with the specified time point and the generation time of the determined snapshot file. The operation commands between the specified time point and the generation time of the snapshot file are determined as incremental operation records and sent to the destination database according to the address of the destination database contained in the data acquisition request.
[0040] The data retrieval request can be a configuration file generated based on a form filled in by the user. The form contains the identifier of the source database that the user wants to restore, the storage address of the source database backup file (although the storage address of the source database backup file can also be determined based on the identifier of the source database, but this would be less convenient, so the storage address of the source database backup file can be added to the data retrieval request), the address of the destination database, the specified time point, and the retrieval requirements, etc.
[0041] The above process requires the participation of the source database. However, the execution of these operations by the source database may affect its normal operation. Therefore, it is advisable to allow a data recovery component, independent of the source database's running process, to determine the source and incremental operation records to be recovered. This data recovery component can be a sub-component of the source database or the destination database, or it can be a component independent of both the source and destination databases.
[0042] When the recovery source and incremental operation records are determined by the data recovery component, the method for the data recovery component to determine the recovery source and incremental operation records includes: the data recovery component receiving a data acquisition request sent by a user, the data acquisition request including the destination database address, the backup file storage address of the source database, data acquisition requirements, and a specified time point; determining the recovery source whose generation time is closest to the specified time point from the backup file storage address of the source database; and determining the incremental operation records between the generation time of the recovery source and the specified time point from the backup file storage address of the source database.
[0043] The data recovery component determines the recovery source and incremental operation records by sending a specified time point and the address of the destination database to the backup file storage address of the source database. The process at the backup file storage address of the source database then determines the recovery source and incremental operation records and sends the determined recovery source and incremental operation records to the destination database.
[0044] Considering the potential problems in the above process: if both the source and destination databases have shards, and the number of shards in the source and destination databases is different, for example, if the source database has 2 shards and the destination database has 4 shards, a backup file in the source database may correspond to multiple shards in the destination database. In this case, the backup file will be unable to be sent because it does not know which specific shard it should be sent to.
[0045] Therefore, the data recovery component determines the recovery source and incremental operation records by first downloading all backup files from the source database's backup file storage address to the data recovery component's storage device. Then, from the downloaded backup files, it selects the snapshot file closest to the specified time point as the recovery source. Simultaneously, it reads each operation command from the operation records, checking its format for correctness. If the format is correct, it determines if the command's timestamp falls between the snapshot file's creation time and the specified time point. If so, it sends the command to the destination database. Because this transmission is done while reading, the destination of each operation command can be determined.
[0046] Specifically, when the data recovery component first downloads and then determines the recovery source and incremental operation records, determining the recovery source whose generation time is closest to the specified time point from the backup file storage address of the source database; determining the incremental operation records between the generation time of the recovery source and the specified time point from the backup file storage address of the source database includes: downloading all backup files from the backup file storage address of the source database; determining the recovery source whose generation time is closest to the specified time point from the downloaded backup files; and determining the incremental operation records between the generation time of the recovery source and the specified time point based on the timestamp of each operation command in all incremental operation records. The destination database receiving the recovery source and incremental operation records includes: the destination database receiving the recovery source and incremental operation records sent by the data recovery component.
[0047] The recovery source received by the destination database can be the entire snapshot file, or the data recovery component can load the recovery source and send each piece of data in the recovery source to the destination database in the form of an operation command (which will retrieve the corresponding data from the recovery source after execution).
[0048] Step 103: Obtain the database corresponding to the recovery source, and after obtaining it, execute the operation command in the incremental operation record to obtain the status of the source database at the specified time point.
[0049] Specifically, to achieve real-time recovery, it's necessary to know what operation commands were executed in the source database at each point in time. This requires the data recovery component or the destination database to obtain timestamped operation records. Furthermore, since there are many operation records, sending only these records would result in a large amount of data being transmitted, increasing the processing load on the destination database and reducing efficiency. Therefore, to improve efficiency, both the recovery source and incremental operation records are sent. After obtaining the database corresponding to the recovery source, the operation commands in the incremental operation records are executed. This reduces the number of operation commands the destination database needs to execute and also improves data retrieval efficiency.
[0050] In step 103, the database corresponding to the recovery source obtained is all the data of the source database at a specified time point. Further filtering is needed to obtain specific data from the source database at the specified time point.
[0051] To obtain the database corresponding to the recovery source, if the destination database has obtained the recovery source file, it can load the recovery source to obtain the database corresponding to the recovery source. If the destination database has received an operation command, it can execute the received operation command to obtain the database corresponding to the recovery source.
[0052] Step 105: Determine the data acquisition requirements, which are used to characterize the specific data.
[0053] Step 107: Extract data that matches the data acquisition requirements from the full data of the state at the specified time point in the source database to obtain specific data in the source database at the specified time point.
[0054] The following section will provide a unified explanation of steps 105 and 107.
[0055] A data retrieval request can be determined by the database management system based on a user's data retrieval request and sent to the destination database. Alternatively, it can be a retrieval instruction containing the retrieval request generated and sent by the data recovery component based on the user's data retrieval request. The retrieval request represents specific data, which can be represented by a data identifier or a regular expression. In the case of a key-value database, the data identifier is the key, and the corresponding data is the value.
[0056] When the acquisition requirement is sent by the data recovery component, the acquisition requirement can be either deleting some data to obtain specific data from the source database at a specified point in time, or retaining specific data to obtain specific data from the source database at a specified point in time.
[0057] Specifically, step 105 may involve receiving a data acquisition request sent by the data recovery component, wherein the data acquisition request includes an operation identifier and a data identifier; the operation identifier is used to represent a deletion operation. Correspondingly, step 107 may involve comparing each data identifier in the full data of the source database at the specified time point with the data identifier in the data acquisition request; if the data identifier matches the data identifier in the data acquisition request, and the operation identifier in the data acquisition request represents a deletion operation, then the data identifier and the corresponding data are deleted; if the data identifier does not match the data identifier in the data acquisition request, and the operation identifier in the data acquisition request represents a deletion operation, then the data identifier and the corresponding data are retained.
[0058] Furthermore, step 105 can also be: receiving a data acquisition request sent by the data recovery component, wherein the data acquisition request includes an operation identifier and a data identifier; the operation identifier is used to represent a retention operation. Correspondingly, step 107 can include: comparing each data identifier in the full data of the source database at the specified time point with the data identifier in the data acquisition request; if the data identifier matches the data identifier in the data acquisition request, and the operation identifier in the data acquisition request represents a retention operation, then the data identifier and the corresponding data are retained; if the data identifier does not match the data identifier in the data acquisition request, and the operation identifier in the data acquisition request represents a retention operation, then the data identifier and the corresponding data are deleted.
[0059] Specifically, retaining or deleting partial data can be achieved by sending operation commands to the target database through the data recovery component. These operation commands are those that the database can execute. These commands can be newly added, but considering that adding a new command would require adaptive modifications to other commands, they can be improvements on existing commands. For example, the `flushall` command can be improved to produce `flushall with pattern` or `flushall without pattern`. Here, `pattern` represents the location where data identifiers or regular expressions can be written. The original meaning of the `flushall` command is to clear everything; `flushall with pattern` means deleting the data and data identifier corresponding to the `pattern` position, while retaining other data and data identifiers; `flushall without pattern` means retaining the dataset data identifier corresponding to the `pattern` position, while deleting other data and data identifiers.
[0060] This way, specific data from the source database at a specified point in time can be obtained, and data recovery can then be performed based on this data. Of course, after obtaining the specific data, it is also possible to process the specific data without performing data recovery.
[0061] Accordingly, this specification also provides a data recovery method for recovering a database containing specific data from the source database at a specified point in time, based on the destination database obtained by the above data acquisition method. For example... Figure 2 As shown, the method includes the following steps: Step 201: Determine the source database and the destination database. The destination database obtains specific data from the source database at a specified time point through the data acquisition method described in the previous embodiment.
[0062] Step 202: The database management terminal replaces the domain name of the source database in the database interface with the domain name of the destination database.
[0063] By replacing the domain name, data recovery can be achieved without interrupting database usage. Furthermore, after recovery, both the destination and source databases can be retained, or the source database can be deleted while the destination database is kept. The specific handling of the source database can be determined based on the user's needs.
[0064] The data acquisition and data recovery methods described in this specification will now be explained in detail through a specific embodiment.
[0065] Suppose user Y creates a Redis database A on a cloud database system called Tair. After using it for a period of time, user Y wants to restore database A to its state at a specific point in time. During the restoration process, user Y wants to restore only specific data (i.e., only the PITR of specific key-value pairs) without restoring all data (key-value pairs). The following steps are required to complete the data restoration: First, such as Figure 3A As shown, the database management console will perform the following steps: Step 301: The database management terminal generates a data recovery configuration file based on the data recovery table entries filled in by the user. The data recovery configuration file includes at least the following: source database identifier, backup file storage address of the source database, destination database address, specified time point, operation identifier, and data identifier.
[0066] The backup file storage address of the source database and the address of the destination database can be represented by IP address, MAC address, or domain name. The specified time point needs to be accurate to the smallest time unit of the database. If the operation identifier is empty, the data identifier defaults to the data to be retained; however, specific data identifiers and operation identifiers can be used to indicate whether to delete or retain specific data. The destination database refers to other Redis database instances that the user owns in this cloud database. If the user does not have other instances, they should be prompted to create a new Redis database instance to complete the data recovery.
[0067] Step 302: The database management terminal sends the generated data recovery configuration file to the data recovery component redis-shake.
[0068] like Figure 3B As shown, after redis-shake receives the recovery configuration file, it will perform the following steps to send the recovery source and incremental operation commands to the destination database.
[0069] Step 311: Parse the received configuration file to determine the identifier of the source database, the address of the destination database, the storage address of the backup file of the source database, and the specified time point for recovery.
[0070] Step 312: Download all backup files of the source database from the backup file storage address of the source database.
[0071] Step 313: Identify and send the recovery source.
[0072] The recovery source is an RDB file. The method for determining the recovery source is to search the backup files for the snapshot file that was generated before a specified time point and whose generation time is closest to the specified time point. This found snapshot file is used as the recovery source. Specifically, the determined recovery source is sent to the address of the destination database.
[0073] Step 314: Determine and send the incremental operation record.
[0074] Once the recovery source is determined, its creation time must first be identified. Then, based on the timestamps of each operation record in the operation log file, it is determined whether the execution time of the operation command falls between the recovery source's creation time and a specified time point. If the result indicates that it falls between these two time points, the operation command is sent to the destination database. These operation commands sent to the destination database are the incremental operation records.
[0075] Step 315: Determine if the data acquisition configuration is empty. If it is not empty, proceed to step 316. If it is empty, end the process.
[0076] After sending the incremental operation record to the destination database, it is necessary to determine whether the user has a need to perform PITR on only some key-value pairs. The data recovery component needs to parse the data acquisition configuration in the recovery configuration file to see if it is empty. If it is empty, it means that the user does not have a need to perform PITR on some key-value pairs, and the process ends. If it is not empty, it means that the user has a need to perform PITR on some key-value pairs.
[0077] Step 316: Generate and send the retrieval command based on the recovery configuration file.
[0078] Specifically, the recovery configuration file contains retrieval configurations for specific retrieval requirements. If the retrieval configuration is not empty, a retrieval command must be sent to the target database. This retrieval command includes a data identifier and an operation identifier. As mentioned above, the retrieval command can be `flushall with pattern` or `flushall without pattern`, the specific meaning of which has already been explained above and will not be repeated here.
[0079] like Figure 3C As shown, after the destination database receives the recovery source, incremental operation file, and retrieval command, it needs to complete the data retrieval. The data retrieval includes the following steps: Step 321: Obtain the database corresponding to the recovery source, and after obtaining it, execute the operation command in the incremental operation record to obtain the status of the source database at the specified time point.
[0080] Step 322: Determine if the number of parameters in the acquisition instruction is less than 2. If it is less than 2, proceed to step 323; otherwise, proceed to step 324.
[0081] The number of parameters in the retrieve command is the same as the number of parameters of the function. The number of parameters of the operation command can be obtained through functions such as argc or argv. If it is less than 2, it means that the retrieve command is the original Redis command flushall, which means that the user does not have a PITR requirement for a specific key-value pair.
[0082] Step 323: Execute the flushall command.
[0083] If the user does not have a PITR requirement for a specific key-value pair, then the traditional flushall instruction needs to be executed.
[0084] Step 324: Determine whether the second parameter is withpattern or withoutpattern. If it is not either of the two, proceed to step 325. If it is either of the two, proceed to step 326.
[0085] Step 325 returns a syntax error.
[0086] Since only two functions, `flushall with pattern` and `flushall without pattern`, have been added to `flushall`, a syntax error will occur if the second parameter is not one of the above.
[0087] Step 326: When the parameter is withpattern, the deletion flag is set to 1; when the parameter is withoutpattern, the retention flag is set to 1.
[0088] Step 327: Parse the pattern and determine if there is a rule with * in the pattern. If it exists, proceed to step 328; otherwise, proceed to step 330.
[0089] Step 328: Set the allkeys bit to 1.
[0090] In regular expressions, * represents the entirety.
[0091] Step 329: Determine if the delete bit or the keep bit is 1. If allkeys is 1 and the delete bit is 1, then proceed to step 323. If allkeys is 1 and the keep bit is 1, then end the process.
[0092] Step 330: Determine if the current key matches the pattern. If it matches, proceed to step 331; otherwise, proceed to step 332.
[0093] Step 331: If the reserved bit is 1, the key-value pair is not deleted; if the deleted bit is 1, the key-value pair is deleted.
[0094] Step 332: If the retention bit is 1, delete the key-value pair; if the deletion bit is 1, retain the key-value pair.
[0095] Step 333: Determine if there are any keys that have not been retrieved in the destination database. If not, end the process. If so, proceed to step 334.
[0096] Step 334, retrieve the next key.
[0097] At this point, the destination database has obtained specific data from the source database at a specified time.
[0098] In addition, such as Figure 3A As shown, the database management console also needs to perform the following steps to complete data recovery: Step 303: If the target database obtains specific data from the source database at a specified time point, replace the domain name of the source database in the database interface with the domain name of the target database.
[0099] This completes the data recovery.
[0100] Corresponding to the embodiments of the foregoing methods, this specification also provides embodiments of the apparatus and the terminal to which it is applied.
[0101] like Figure 4 As shown, Figure 4 This is a block diagram illustrating a data acquisition device according to an exemplary embodiment of this specification, applied to a destination database, for enabling the destination database to acquire specific data from a source database at a specified time point; the device includes: The receiving module 410 is used to receive the recovery source and incremental operation records; the recovery source is a snapshot file of the source database, and the incremental operation records are operation commands executed on the source database between the generation time of the snapshot file and the specified time point, wherein the generation time of the recovery source is earlier than the specified time point.
[0102] The acquisition module 420 is used to acquire the database corresponding to the recovery source, and after the acquisition is completed, execute the operation command in the incremental operation record to obtain the status of the source database at the specified time point.
[0103] The determination module 430 is used to determine the data acquisition requirements, which are used to characterize the specific data.
[0104] The extraction module 440 is used to extract data that matches the data acquisition requirements from the full data of the state at the specified time point in the source database, so as to obtain specific data in the source database at the specified time point.
[0105] The recovery source and the incremental operation record are determined by the data recovery component. The method by which the data recovery component determines the recovery source and the incremental operation record includes: the data recovery component receiving a data acquisition request sent by a user, the data acquisition request including the destination database address, the backup file storage address of the source database, data acquisition requirements, and a specified time point; determining the recovery source whose generation time is closest to the specified time point from the backup file storage address of the source database; and determining the incremental operation record between the generation time of the recovery source and the specified time point from the backup file storage address of the source database.
[0106] When the data recovery component determines the recovery source and incremental operation records, it determines the recovery source whose generation time is closest to the specified time point from the backup file storage address of the source database; it then determines the incremental operation records between the generation time of the recovery source and the specified time point from the backup file storage address of the source database, including: downloading all backup files from the backup file storage address of the source database; determining the recovery source whose generation time is closest to the specified time point from the downloaded backup files; and determining the incremental operation records between the generation time of the recovery source and the specified time point based on the timestamp of each operation command in all incremental operation records. The receiving module 410 is specifically used for: the destination database receiving the recovery source and incremental operation records sent by the data recovery component.
[0107] The determining module 430 is specifically used to: receive a data acquisition request sent by the data recovery component, wherein the data acquisition request includes an operation identifier and a data identifier; the operation identifier is used to represent a deletion operation. The extraction module 440 is specifically used to: compare each data identifier in the full data of the source database at the specified time point with the data identifier in the data acquisition request; if the data identifier matches the data identifier in the data acquisition request, and the operation identifier in the data acquisition request represents a deletion operation, then the data identifier and the corresponding data are deleted; if the data identifier does not match the data identifier in the data acquisition request, and the operation identifier in the data acquisition request represents a deletion operation, then the data identifier and the corresponding data are retained.
[0108] Furthermore, the determining module can also be specifically used to: receive a data acquisition request sent by the data recovery component, wherein the data acquisition request includes an operation identifier and a data identifier; the operation identifier is used to represent a retention operation. The extraction module 440 is specifically used to: compare each data identifier in the full data of the source database at the specified time point with the data identifier in the data acquisition request; if the data identifier matches the data identifier in the data acquisition request, and the operation identifier in the data acquisition request represents a retention operation, then the data identifier and the corresponding data are retained; if the data identifier does not match the data identifier in the data acquisition request, and the operation identifier in the data acquisition request represents a retention operation, then the data identifier and the corresponding data are deleted.
[0109] In addition, such as Figure 5 As shown, Figure 5 This specification is a block diagram illustrating a data recovery apparatus according to an exemplary embodiment, used to recover a database containing specific data from a source database at a specified point in time; the apparatus includes: The database determination module 510 is used to determine the source database and the destination database, wherein the destination database obtains specific data from the source database at a specified time point through the data acquisition method described above.
[0110] The domain name replacement module 520 is used by the database management end to replace the domain name of the source database in the database interface with the domain name of the destination database.
[0111] The specific implementation process of the functions and roles of each module in the above device can be found in the implementation process of the corresponding steps in the above method, and will not be repeated here.
[0112] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to in the description of the method embodiments. The device embodiments described above are merely illustrative. The modules described as separate components may or may not be physically separate, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed across multiple network modules. Some or all of the modules can be selected to achieve the purpose of the solution in this specification according to actual needs. Those skilled in the art can understand and implement this without creative effort.
[0113] like Figure 6 As shown, Figure 6 This diagram illustrates a hardware structure of an electronic device housing an embodiment of a data acquisition or data recovery device. The device can be a destination database or a database management terminal. It may include a processor 1010, a memory 1020 for storing processor-executable instructions, an input / output interface 1030, a communication interface 1040, and a bus 1050. The processor 1010, memory 1020, input / output interface 1030, and communication interface 1040 are internally connected to each other via the bus 1050.
[0114] The processor 1010 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits. The processor implements the above-mentioned data acquisition or data recovery methods by running executable instructions.
[0115] The memory 1020 can be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 1020 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, the relevant program code is stored in the memory 1020 and is called and executed by the processor 1010.
[0116] The input / output interface 1030 is used to connect input / output modules to realize information input and output. The input / output modules can be configured as engines in the device (not shown in the figure) or externally connected to the device to provide corresponding functions. Input devices may include keyboards, mice, touch screens, microphones, various sensors, etc., and output devices may include displays, speakers, vibrators, indicator lights, etc.
[0117] The communication interface 1040 is used to connect a communication module (not shown in the figure) to enable communication between this device and other devices. The communication module can communicate via wired means (such as USB, Ethernet cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).
[0118] Bus 1050 includes a pathway for transmitting information between the various engines of the device, such as processor 1010, memory 1020, input / output interface 1030, and communication interface 1040.
[0119] It should be noted that although the above-described device only shows the processor 1010, memory 1020, input / output interface 1030, communication interface 1040, and bus 1050, in specific implementations, the device may also include other engines necessary for normal operation. Furthermore, those skilled in the art will understand that the above-described device may only include the engines necessary for implementing the embodiments of this specification, and not necessarily all the engines shown in the figures.
[0120] This specification also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the aforementioned data acquisition method or data recovery method. The computer program may store only the data acquisition method or only the data recovery method.
[0121] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0122] In addition, this specification also provides a computer program that, when run, implements the above-described data acquisition method or data recovery method.
[0123] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0124] The foregoing has described specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are possible or may be advantageous.
Claims
1. A data acquisition method for enabling a destination database to acquire specific data from a source database at a specified point in time; wherein, The source database is used to receive data acquisition requests from users; the data acquisition request includes data acquisition requirements characterizing the specific data, the data acquisition requirements including an operation identifier and a data identifier, the operation identifier being used to characterize a deletion operation or a retention operation; the method includes: The destination database data recovery component determines the recovery source and incremental operation records based on the data acquisition request; the recovery source is a snapshot file of the source database, and the incremental operation records are operation commands executed on the source database between the generation time of the snapshot file and the specified time point, wherein the generation time of the recovery source is earlier than the specified time point; Obtain the database corresponding to the recovery source, and after obtaining it, execute the operation command in the incremental operation record to obtain the status of the source database at the specified time point; The operation commands sent by the data recovery component are obtained. The types of the operation commands include: existing flushall commands and newly added commands obtained by improving existing flushall commands. The newly added commands include flushall with pattern commands and flushall without pattern commands, where pattern is the data identifier. If the operation command is an existing flushall command, then clear all; If the operation command is the flushall with pattern command, then delete the data and data identifier corresponding to the pattern position, and retain the other data and data identifier; If the operation command is the flushall without pattern command, then the data and data identifier corresponding to the pattern position are retained, and other data and data identifiers are deleted.
2. The method according to claim 1, wherein the method for the data recovery component to determine the recovery source and incremental operation record includes: The data recovery component receives a data retrieval request sent by the user. The data retrieval request includes the destination database address, the backup file storage address of the source database, the data retrieval requirements, and the specified time point. Determine the recovery source whose generation time is closest to the specified time point from the storage address of the backup file of the source database; Determine the incremental operation record between the generation time of the recovery source and the specified time point from the storage address of the backup file of the source database.
3. The method according to claim 2, The backup file storage address of the source database is used to determine the recovery source whose generation time is closest to the specified time point; Determine the incremental operation records between the generation time of the recovery source and the specified time point from the backup file storage address of the source database, including: Download all backup files from the backup file storage address of the source database; The recovery source whose generation time is closest to the specified time point is determined from the downloaded backup file, and the incremental operation records between the generation time of the recovery source and the specified time point are determined based on the timestamp of each operation command in all incremental operation records. The destination database receives the recovery source and incremental operation records, including: The destination database receives the recovery source and incremental operation records sent by the data recovery component.
4. A data recovery method, applied to a database management terminal, for recovering a database containing specific data from a source database at a specified point in time; the method includes: The source database and the destination database are determined, wherein the destination database obtains specific data from the source database at a specified time point through the method described in any one of claims 1-3; The database management terminal replaces the domain name of the source database in the database interface with the domain name of the destination database.
5. A data acquisition device, applied to a destination database, for enabling the destination database to acquire specific data from a source database at a specified time point; The source database is used to receive data acquisition requests from users; the data acquisition request includes data acquisition requirements characterizing the specific data, the data acquisition requirements including an operation identifier and a data identifier, the operation identifier being used to characterize a deletion operation or a retention operation; the device includes: The receiving module is used to acquire the recovery source and incremental operation records determined by the data recovery component of the source database based on the data acquisition request; the recovery source is a snapshot file of the source database, and the incremental operation records are: operation commands executed on the source database between the generation time of the snapshot file and the specified time point, wherein the generation time of the recovery source is earlier than the specified time point; The determination module is used to obtain operation commands sent by the data recovery component. The types of operation commands include: existing flushall commands and newly added commands derived from improvements to existing flushall commands. The newly added commands include the flushall with pattern command and the flushall without pattern command, where pattern is the data identifier. If the operation command is an existing flushall command, all data is cleared. If the operation command is the flushall with pattern command, the data and data identifier corresponding to the pattern position are deleted, while other data and data identifiers are retained. If the operation command is the flushall without pattern command, the data and data identifier corresponding to the pattern position are retained, while other data and data identifiers are deleted.
6. A data recovery apparatus for recovering a database containing specific data from a source database at a specified point in time; the apparatus comprising: A database determination module is used to determine the source database and the destination database, wherein the destination database obtains specific data from the source database at a specified time point through the method described in any one of claims 1-3; The domain name replacement module is used by the database management end to replace the domain name of the source database in the database interface with the domain name of the destination database.
7. An electronic device, comprising: processor; Memory used to store processor-executable instructions; The processor implements the method as described in any one of claims 1-4 by executing the executable instructions.
8. A computer-readable storage medium storing computer instructions that, when executed by a processor, implement the method as described in any one of claims 1-4.
9. A computer program that, when executed, implements the method as described in any one of claims 1-4.
Citation Information
Patent Citations
Data backup and restoration method and destination sever system for backup
CN103345435A
Data output method and apparatus
CN106411975A
