Embedded system data backup and recovery method, device and medium

By introducing the pre-write logging data file path and verification code into the embedded device, the problem of data inconsistency between the main and secondary partitions after abnormal power outage of the embedded device is solved, and the consistency and reliability recovery of the data file is achieved.

CN120508443APending Publication Date: 2025-08-19TIANDI CHANGZHOU AUTOMATION +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510480791.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-17
Publication Date
2025-08-19

AI Technical Summary

Technical Problem

After an abnormal power outage of embedded devices, the data files of the main and secondary partitions are prone to inconsistencies, and the existing technology is difficult to effectively solve.

Method used

Introduce independent pre-write logs to record data file paths and verification codes, and ensure the consistency of data files by verifying the integrity of pre-write logs and avoiding deep coupling with integrity and timestamps.

Benefits of technology

After an abnormal power outage of the embedded device, the consistency of the primary and secondary partition data files is ensured through verification of the pre-write log, avoiding the deep coupling of the consistency of the data file with its own integrity checksum time stamp marks, and improving the accuracy and reliability of data recovery.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120508443A_ABST
    Figure CN120508443A_ABST
Patent Text Reader

Abstract

The invention relates to an embedded system data backup and recovery method and device and a medium thereof in the technical field of embedded systems. The method comprises the steps of log before writing, data forward backup and data reverse recovery. According to the method, the problem of inconsistency of the data files of the main partition and the auxiliary partition after the embedded equipment is restarted after abnormal power failure at any time point during data backup is solved, the independent pre-write log is introduced, the consistency of the data files is ensured by checking the integrity of the pre-write log, and the reliability of the data files is improved. And the consistency of the data file is prevented from being deeply coupled with self integrity verification and timestamp marking.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of embedded systems, and in particular to an embedded system data backup and recovery method, device and medium thereof. Background Art

[0002] In today's digital age, embedded devices play an indispensable role. From smart homes to medical equipment and coal mining equipment, embedded devices, with their specialized functions and high performance, have greatly improved convenience and productivity. However, if an embedded device experiences a power outage during a write operation, it can cause a variety of problems, ranging from file loss to disk corruption and inability to mount. To address power outages, adding a backup battery is a common hardware solution. However, in practice, this approach has significant drawbacks. On the one hand, the introduction of a backup battery increases device cost; on the other hand, in some specialized scenarios, such as coal mining environments, strict intrinsic safety requirements are imposed on the equipment. Conventional batteries struggle to meet the explosion-proof and leak-proof requirements of intrinsic safety standards.

[0003] Given hardware limitations, exploring and implementing embedded system file backup and recovery from a software perspective is of great practical significance. A common data backup method is to partition the disk storing user data into primary and secondary partitions. When an embedded device boots up, the system prioritizes data in the primary partition, while the secondary partition assumes data backup responsibilities. If data in the primary partition changes, the system backs up the changes from the primary partition to the secondary partition, ensuring data consistency between the two partitions. If the system experiences a power outage while writing data to the primary partition, upon device restart, the system checks the data in both partitions and determines how to restore the data based on the test results. Two common methods for checking integrity are available. One is to verify the integrity of the data files. However, in actual operation, the power outage may occur when the primary partition has completed its data update but before the secondary partition has begun its update. In this case, while the data in the primary and secondary partitions remains intact, the contents of the two partitions are actually inconsistent. The second method is to use timestamps to determine whether data is up to date. However, given that embedded devices may operate independently without a network connection and lack battery backup for time protection, real-time time calibration is impossible. Therefore, relying on timestamps to determine whether data is up to date also faces significant uncertainty. Summary of the Invention

[0004] The purpose of the present invention is to provide an embedded system data backup and recovery method, which solves the problem of inconsistency between primary and secondary partition data files after an abnormal power outage and restart at any time point during data backup of an embedded device. An independent write-ahead log is introduced to ensure the consistency of data files by verifying the integrity of the write-ahead log, thereby avoiding the deep coupling of the consistency of data files with their own integrity verification and timestamp marking.

[0005] Based on the above technical problems, the present invention provides a method for backing up and restoring data of an embedded device, comprising the following steps:

[0006] (1) Write-before log, which records the information of data forward backup;

[0007] (2) Data forward backup, describing the process of copying data files from the primary partition to the secondary partition;

[0008] (3) Data reverse recovery, describing the process of copying data files from the secondary partition to the primary partition.

[0009] The content of the write-before log includes a data file path and a check code. The data file path is the absolute path of the data file whose content has changed in the primary partition, and the check code is a check code calculated by a specific algorithm describing the absolute path of the data file.

[0010] Furthermore, when creating a write-before log, the above-mentioned data file path and check code are written into the log together; when the system is restarted for data reverse recovery, the front-end absolute path in the write-before log is read out and the check code is recalculated, and compared with the back-end check code in the write-before log to verify the integrity of the write-before log; if the two check codes are consistent, it means that the write-before log is complete, otherwise it is incomplete.

[0011] Specifically, the data forward backup includes the following steps:

[0012] S1, check whether the primary partition data file has been changed;

[0013] S2, after detecting data changes, the system obtains the absolute path of the data file in the primary partition;

[0014] S3, performing a specific algorithm verification based on the absolute path of the data file obtained in step S2, and obtaining a verification code;

[0015] S4: Check whether the secondary partition has a write-ahead log. If yes, proceed to S6; if not, proceed to S5.

[0016] S5: Create a new write-ahead log file in the secondary partition;

[0017] S6, open the write-before log, write the data file path obtained in step S2 and the check code obtained in step S3 into the write-before log, and close it;

[0018] S7, synchronize the data files from the primary partition to the corresponding location of the secondary partition;

[0019] S8: Open the write-before log, delete the data file path and check code written in step S6, and check whether the write-before log file is empty. If so, proceed to S9; otherwise, complete the data backup.

[0020] S9: Delete the write-ahead log.

[0021] Specifically, the data reverse recovery includes the following steps:

[0022] S1: Check whether the primary partition and secondary partition can be mounted. If both can be mounted, go to S4; otherwise, go to S2.

[0023] S2, format the partition that cannot be mounted;

[0024] S3: Completely copy the data from another partition to the currently formatted partition to complete the data recovery.

[0025] S4: Check whether the secondary partition has a write-ahead log. If so, it indicates that the system was performing data backup before the device was powered off, and the entire forward data backup process was not completed. Then, the process proceeds to S5; otherwise, the process proceeds to S8.

[0026] S5, obtain the data file path and check code in the write-before log, check whether the two match to confirm the integrity of the write-before log, if the write-before log is complete, proceed to S6, otherwise proceed to S7;

[0027] S6, according to the path obtained in S4, forward sync the data files from the primary partition to the secondary partition, completing the data backup operation that was not completed before the device power off;

[0028] S7, delete the write-ahead log;

[0029] S8, comparing the data differences between the secondary partition and the primary partition, restoring the data of the secondary partition to the primary partition, and completing this data recovery.

[0030] In embedded devices, the system forward synchronizes data files from the primary partition to the secondary partition for data backup. If a primary partition's data files become corrupted due to an unexpected power outage, the secondary partition can restore the previously backed-up data files to the primary partition, preventing data loss and ensuring data consistency. Some previously proposed methods only consider power outage time point 4. If a power outage occurs while the secondary partition's data files are being accessed, the secondary partition's data files are incomplete, requiring subsequent synchronization based on data file integrity or timestamps. Other methods consider power outage time points 3 and 5. Therefore, a custom log is added to record whether the current data files have been fully backed up in the secondary partition. However, ignoring the addition of a custom log also increases the number of power outages in the entire forward data backup process. If a power outage occurs during the creation or deletion of the custom log, the entire custom log will be incomplete, potentially causing the custom log content to be partially updated or not updated at all, leading to errors in subsequent recovery processes that rely on the log.

[0031] The data backup method of the present invention fully considers seven power outage time points when forward backing up data to the secondary partition, including:

[0032] When the power outage occurs before the write-ahead log creation phase, that is, power outage time point 1;

[0033] When the power outage occurs when the write-ahead log is created, that is, power outage time point 2;

[0034] When the power outage occurs after the write-ahead log is created and before the backup phase begins, that is, at power outage time point 3;

[0035] When the power outage occurs in the backup data file, that is, the power outage time point 4;

[0036] When the power outage occurs after the data backup phase and before the write-ahead log deletion phase, that is, power outage time point 5;

[0037] When the power outage occurs during the write-ahead log deletion, that is, power outage time point 6;

[0038] When the power outage occurs after the write-ahead log deletion phase, that is, power outage time point 7.

[0039] The present invention also provides a computer device, comprising:

[0040] a memory for storing program instructions;

[0041] The processor is used to execute the program instructions to implement the above-mentioned embedded device data backup and recovery method.

[0042] The present invention also provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program. When the computer program is executed by a processor, the processor implements the above-mentioned embedded device data backup and recovery method.

[0043] The beneficial effects of the present invention are:

[0044] (1) The present invention adds a write-ahead log to record data information in the current data forward backup process. If a power outage occurs during the data backup phase, resulting in an incomplete secondary partition data file, a forward backup is performed again based on the write-ahead log at startup to ensure the consistency of the data file.

[0045] (2) By synchronously writing the absolute path check code of the data file into the write-before log, the integrity of the write-before log is guaranteed. If a power failure occurs during the write-before log creation and deletion stages, resulting in an incomplete write-before log in the secondary partition, the integrity of the write-before log can be checked at startup to determine whether the data files to be backed up are consistent in the primary and secondary partitions.

[0046] (3) The present invention does not need to pay attention to the integrity and timestamps of the data files corresponding to the primary partition and the secondary partition. The consistency of the data files can be guaranteed only based on the integrity of the pre-write log in the secondary partition and corresponding processing, thus avoiding the deep coupling of the consistency of the data files with their own attributes. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] Figure 1 This is a schematic diagram of the embedded device data backup and recovery method of the present invention;

[0048] Figure 2 A schematic diagram of the content of a write-before log of the present invention;

[0049] Figure 3 This is a flow chart of data forward backup of the present invention;

[0050] Figure 4 A flowchart of data reverse recovery according to the present invention;

[0051] Figure 5 Schematic diagram of power outage time points for forward data backup according to the present invention. DETAILED DESCRIPTION

[0052] The preferred embodiments of the present invention are described in detail below with reference to the accompanying drawings so that the advantages and features of the present invention can be more easily understood by those skilled in the art, thereby making a clearer and more precise definition of the protection scope of the present invention.

[0053] Example 1

[0054] like Figure 1The embedded device data backup and recovery method shown includes the following steps:

[0055] (1) Write-before log, which records the information of data forward backup;

[0056] (2) Data forward backup, describing the process of copying data files from the primary partition to the secondary partition;

[0057] (3) Data reverse recovery, describing the process of copying data files from the secondary partition to the primary partition.

[0058] The content of the write-before log includes the data file path / opt / date1 and the check code c75d40c5, such as Figure 2 As shown, the data file path is an absolute path in the primary partition describing the data file whose content has changed, and the check code is a check code calculated by a specific algorithm describing the absolute path of the data file.

[0059] Furthermore, when creating a write-before log, the above-mentioned data file path and check code are written into the log together; when the system is restarted for data reverse recovery, the front-end absolute path in the write-before log is read out and the check code is recalculated, and compared with the back-end check code in the write-before log to verify the integrity of the write-before log; if the two check codes are consistent, it means that the write-before log is complete, otherwise it is incomplete; the data file consistency describes that the data file contents specified by the primary partition and the secondary partition are the same.

[0060] Specifically, if Figure 3 As shown, the data forward backup includes the following steps:

[0061] S1, check whether the primary partition data file has been changed;

[0062] S2, after detecting data changes, the system obtains the absolute path of the data file in the primary partition;

[0063] S3, performing a specific algorithm verification based on the absolute path of the data file obtained in step S2, and obtaining a verification code;

[0064] S4: Check whether the secondary partition has a write-ahead log. If yes, proceed to S6; if not, proceed to S5.

[0065] S5: Create a new write-ahead log file in the secondary partition;

[0066] S6, open the write-before log, write the data file path obtained in step S2 and the check code obtained in step S3 into the write-before log, write the data file path (file name) and the check code, and close it;

[0067] S7, synchronize the data files from the primary partition to the corresponding location of the secondary partition;

[0068] S8: Open the write-before log, delete the data file path (file name) and check code written in step S6, and check whether the write-before log file is empty. If so, proceed to S9, otherwise complete the data backup;

[0069] S9: Delete the write-ahead log.

[0070] Specifically, if Figure 4 As shown, the data reverse recovery includes the following steps:

[0071] S1: Check whether the primary partition and secondary partition can be mounted. If both can be mounted, go to S4; otherwise, go to S2.

[0072] S2, format the partition that cannot be mounted;

[0073] S3: Completely copy the data from another partition to the currently formatted partition to complete the data recovery.

[0074] S4: Check whether the secondary partition has a write-ahead log. If so, it indicates that the system was performing data backup before the device was powered off, and the entire forward data backup process was not completed. Then, the process proceeds to S5; otherwise, the process proceeds to S8.

[0075] S5, obtain the data file path (file name) and check code in the write-before log, check whether the two match to confirm the integrity of the write-before log, if the write-before log is complete, go to S6, otherwise go to S7;

[0076] S6, according to the path obtained in S4, forward sync the data files from the primary partition to the secondary partition, completing the data backup operation that was not completed before the device power off;

[0077] S7, delete the write-ahead log;

[0078] S8, comparing the data differences between the secondary partition and the primary partition, restoring the data of the secondary partition to the primary partition, and completing this data recovery.

[0079] The data backup method of the present invention fully considers seven power failure time points when the data is forward backed up to the secondary partition, such as Figure 5 Shown, including

[0080] If the power outage occurs before the write-ahead log is created, that is, at power outage time point 1: there is no write-ahead log at this time, so it can be considered that the data file has not been forward backed up. In this case, during the system restart and recovery phase, the previous version of the data file in the secondary partition will overwrite the current data file in the primary partition;

[0081] If a power outage occurs while the write-ahead log is being created (point 2), the data file path in the write-ahead log will not match the checksum. At this point, the system has not yet entered the backup phase. During system restart and recovery, the write-ahead log will be deleted, and a reverse recovery will be performed. The previously backed-up data files in the secondary partition will overwrite the current data files in the primary partition.

[0082] If a power outage occurs after the write-ahead log is created and before the backup phase begins, that is, at power outage time point 3: the write-ahead log is complete, but the backup phase has not yet begun. During the system restart and recovery phase, the system obtains the write-ahead log and determines its integrity. Based on the write-ahead log content, a forward backup of the data files is performed to complete the backup work that was not completed before the power outage. After the forward backup is completed, the write-ahead log is deleted, and a reverse recovery process is performed to ensure the consistency of all files.

[0083] If a power outage occurs in the backup data file, that is, power outage time point 4: the write-ahead log is complete, but the backup file of the secondary partition is incomplete, then during the system restart recovery phase, the system can still obtain the write-ahead log and determine its integrity. Based on the write-ahead log content, a forward backup of the data file is performed to complete the backup work that was not completed before the power outage. After the forward backup is completed, the write-ahead log is deleted, and the reverse recovery process is performed again to ensure the consistency of all files;

[0084] If the power outage occurs after the data backup phase and before the write-ahead log deletion phase, that is, at power outage time point 5: the write-ahead log is complete, and the backup file of the secondary partition is complete, then during the system restart recovery phase, the system can still obtain the write-ahead log and determine its integrity. Based on the contents of the write-ahead log, a forward backup of the data file is performed. Although the backup has already been completed, a new backup will not affect the consistency of the primary and secondary partition data files. After the forward backup is completed, the write-ahead log is deleted, and the reverse recovery process is performed again to ensure the consistency of all files;

[0085] If the power outage occurs during the deletion of the write-ahead log, that is, at power outage time 6: the write-ahead log is incomplete, but the secondary partition has completed the data file backup, then during the system restart and recovery phase, the system directly deletes the write-ahead log and performs a reverse recovery. At this time, the data files in the secondary partition are consistent with the primary partition. Even if the reverse recovery is performed, the data files in the primary and secondary partitions can be guaranteed to be consistent and up-to-date.

[0086] When the power outage occurs after the write-ahead log deletion phase, that is, power outage time point 7: At this time, there is no write-ahead log, and the secondary partition has completed the data file backup. Then, during the system restart and recovery phase, the system directly performs a reverse recovery. At this time, the secondary partition data file is consistent with the primary partition, which can ensure that the data files in the primary and secondary partitions are consistent and up-to-date.

[0087] Example 2

[0088] The present invention also provides a computer device, including a memory and a processor, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by the processor to implement the embedded device data backup and recovery method provided in Example 1.

[0089] Example 3

[0090] The present invention also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the processor implements the embedded device data backup and recovery method as described in the first embodiment.

[0091] Finally, it should be noted that the above embodiments are only specific implementation methods of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The scope of protection of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that any person skilled in the art can modify or easily conceive of changes to the technical solutions described in the above embodiments within the technical scope disclosed by the present invention, or replace some of the technical features therein with equivalents. Such modifications, changes or replacements do not deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be based on the scope of protection of the claims.

Claims

1. A method for backing up and restoring data of an embedded device, characterized in that: The steps include: (1) Write-before log, which records the information of data forward backup; (2) Data forward backup, the process of copying data files from the primary partition to the secondary partition; (3) Data reverse recovery: the process of copying data files from the secondary partition to the primary partition.

2. The embedded device data backup and recovery method according to claim 1, characterized in that: The content of the write-before log includes a data file path and a check code. The data file path is an absolute path in the primary partition describing the data file whose content has changed. The check code is a check code calculated by a specific algorithm describing the absolute path of the data file.

3. The embedded device data backup and recovery method according to claim 2, characterized in that: When creating a write-before log, the above-mentioned data file path and checksum are written into the log together. When the system is restarted for data reverse recovery, the front-end absolute path in the write-before log is read and the checksum is recalculated. The checksum is then compared with the back-end checksum in the write-before log to verify the integrity of the write-before log. If the two checksums are consistent, the write-before log is complete, otherwise it is incomplete.

4. The embedded device data backup and recovery method according to claim 3, characterized in that: The data forward backup includes the following steps: S1, check whether the primary partition data file has been changed; S2, after detecting data changes, the system obtains the absolute path of the data file in the primary partition; S3, performing a specific algorithm verification based on the absolute path of the data file obtained in step S2, and obtaining a verification code; S4: Check whether the secondary partition has a write-ahead log. If yes, proceed to S6; if not, proceed to S5. S5: Create a new write-ahead log file in the secondary partition; S6, open the write-before log, write the data file path obtained in step S2 and the check code obtained in step S3 into the write-before log, and close it; S7, synchronize the data files from the primary partition to the corresponding location of the secondary partition; S8: Open the write-before log, delete the data file path and check code written in step S6, and check whether the write-before log file is empty. If so, proceed to S9; otherwise, complete the data backup. S9: Delete the write-ahead log.

5. The embedded device data backup and recovery method according to claim 4, characterized in that: The data reverse recovery comprises the following steps: S1: Check whether the primary partition and secondary partition can be mounted. If both can be mounted, go to S4; otherwise, go to S2. S2, format the partition that cannot be mounted; S3: Completely copy the data from another partition to the currently formatted partition to complete the data recovery. S4: Check whether the secondary partition has a write-ahead log. If so, it indicates that the system was performing data backup before the device was powered off, and the entire forward data backup process was not completed. Then, the process proceeds to S5; otherwise, the process proceeds to S8. S5, obtain the data file path and check code in the write-before log, check whether the two match to confirm the integrity of the write-before log, if the write-before log is complete, proceed to S6, otherwise proceed to S7; S6, according to the path obtained in S4, forward sync the data files from the primary partition to the secondary partition, completing the data backup operation that was not completed before the device power off; S7, delete the write-ahead log; S8, comparing the data differences between the secondary partition and the primary partition, restoring the data of the secondary partition to the primary partition, and completing this data recovery.

6. The embedded device data backup and recovery method according to claim 5, characterized in that: There are seven power failure time points when data is forward backed up to the secondary partition; When the power outage occurs before the write-ahead log creation phase, that is, power outage time point 1; When the power outage occurs when the write-ahead log is created, that is, power outage time point 2; When the power outage occurs after the write-ahead log is created and before the backup phase begins, that is, at power outage time point 3; When the power outage occurs in the backup data file, that is, the power outage time point 4; When the power outage occurs after the data backup phase and before the write-ahead log deletion phase, that is, power outage time point 5; When the power outage occurs during the write-ahead log deletion, that is, power outage time point 6; When the power outage occurs after the write-ahead log deletion phase, that is, power outage time point 7.

7. A computer device, characterized in that: include: a memory for storing program instructions; A processor is used to execute the program instructions to implement the embedded device data backup and recovery method according to any one of claims 1 to 6.

8. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program. When the computer program is executed by a processor, the processor implements the embedded device data backup and recovery method according to any one of claims 1 to 6.