Power failure detection and data backup method
By monitoring the state changes of the serial port pin state of the computer equipment to detect power failure and back up data when power failure is detected, the problem of high cost in the prior art requiring additional power failure detection modules is solved, and efficient data backup and risk reduction are achieved.
Patent Information
- Application Number
- CN202411871487.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-18
- Publication Date
- 2025-04-11
AI Technical Summary
The existing power-down detection and data backup methods require the installation of additional power-down detection modules, resulting in higher costs.
By electrically connecting the serial port pin to the power input terminal of the computer device, the state changes of the serial port pin are monitored to detect power loss, and when power loss is detected, the data stored in the shared memory is stored in memory for backup.
It realizes that without modifying the computer hardware, detecting abnormal power failure and backing up data, reducing the risk of data loss and saving costs.
Smart Images

Figure CN119806908A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of computer equipment, and in particular to a power failure detection and data backup method. Background Art
[0002] In industrial computer equipment, the operating system is responsible for managing hardware resources and running applications. However, in some cases, unexpected power outages may interrupt ongoing data write operations, causing damage to the file system and key configuration files. This damage not only affects the integrity of the data, but may also cause the device to fail to start or operate normally, thereby affecting the stability of the production process and equipment.
[0003] The existing technical solution proposes to install a power failure detection module on the device to monitor the power status, and when it is detected that the power is about to fail, execute the shutdown procedure and back up the data in time, so as to ensure data security. Summary of the invention
[0004] The main purpose of the present application is to provide a power failure detection and data backup method, aiming to solve the problem of high cost caused by the need to install an additional power failure detection module in the existing power failure detection and data backup method.
[0005] To achieve the above-mentioned purpose, the present application proposes a power failure detection and data backup method applied to a computer device, wherein the serial port pin of the computer device is electrically connected to the power input terminal of the computer device, and the computer device also includes a memory, and the method includes:
[0006] In response to a power-on instruction, a backup process is started and a shared memory is created;
[0007] When the system is running, the data required to be backed up when the system is currently running is read, and the data required to be backed up is stored in the shared memory;
[0008] Monitoring whether the state of the serial port pin changes to detect whether the power supply connected to the power input terminal of the computer device is powered off;
[0009] When a change in the state of the serial port pin is detected and it is determined that the computer device is powered off, the data to be backed up stored in the shared memory is stored in the storage for backup.
[0010] In one embodiment, after the step of monitoring a change in the state of the serial port pin and determining that the computer device is powered off, the method further includes:
[0011] The data to be backed up stored in the shared memory is sent to the server for backup.
[0012] In one embodiment, after the step of storing the required backup data stored in the shared memory to the storage for backup, the method further comprises:
[0013] In response to the boot instruction, the required backed-up data is restored to the computer device.
[0014] In one embodiment, the data to be backed up includes encrypted data, and before the step of storing the data to be backed up stored in the shared memory to the storage for backing up, the method further includes:
[0015] Inputting the data to be backed up stored in the shared memory into a preset encryption algorithm for encryption to generate corresponding encrypted data;
[0016] The step of storing the required backup data stored in the shared memory to the storage device for backup comprises:
[0017] The encrypted data is stored in the memory for backup.
[0018] In one embodiment, after the step of storing the encrypted data in the memory for backup, the method further comprises:
[0019] In response to a power-on instruction, the encrypted data is input into a preset decryption algorithm corresponding to the preset encryption algorithm for decryption to obtain decrypted data;
[0020] The decrypted data is restored to the computer device.
[0021] In one embodiment, before the step of storing the data to be backed up stored in the shared memory to the storage device for backing up, the method further includes:
[0022] Inputting the data to be backed up stored in the shared memory into a preset data summary algorithm to generate a corresponding first data summary;
[0023] The step of storing the required backup data stored in the shared memory to the storage device for backup comprises:
[0024] The data to be backed up and the first data summary stored in the shared memory are stored in the storage device for backup; wherein the first data summary is used to verify whether the data to be backed up is complete.
[0025] In one embodiment, after the step of backing up the data to be backed up and the first data summary stored in the shared memory, the method further includes:
[0026] In response to a power-on instruction, obtaining first backup data of the memory; wherein the first backup data includes the data to be backed up and the first data summary stored in the shared memory last time;
[0027] Inputting the data to be backed up in the first backup data into the preset data summary algorithm to generate a corresponding second data summary;
[0028] When the first data digest matches the second data digest successfully, the required backup data in the first backup data is restored to the computer device.
[0029] In one embodiment, the data to be backed up stored in the shared memory is also sent to the server for backup; after the step of inputting the data to be backed up in the first backup data into the preset data summary algorithm to generate a corresponding second data summary, the method further includes:
[0030] When the first data digest fails to match the second data digest, obtaining second backup data from the server; wherein the second backup data includes the required backup data stored in the shared memory last backed up by the server;
[0031] Inputting the second backup data into the preset data summary algorithm to generate a corresponding third data summary;
[0032] When the first data digest successfully matches the third data digest, the second backup data is restored to the computer device.
[0033] In one embodiment, when a change in the state of the serial port pin is detected and it is determined that the computer device is powered off, the step of storing the data to be backed up stored in the shared memory to the storage for backing up includes:
[0034] When a change in the state of the serial port pin is detected and it is determined that the computer device is powered off, the required backup data stored in the shared memory is stored in the storage device in a direct read-write manner of an unbuffered I / O.
[0035] In one embodiment, the computer device includes a capacitor for supplying power when the computer device is powered off. After the step of storing the required backup data stored in the shared memory to the storage for backup when a change in the state of the serial port pin is detected and it is determined that the computer device is powered off, the method further includes:
[0036] In response to the data backup completion instruction stored in the shared memory, a shutdown instruction is executed to shut down the computer device before the capacitor is fully discharged.
[0037] One or more technical solutions proposed in this application have at least the following technical effects:
[0038] In response to the power-on instruction, the backup process is started and a shared memory is created. When the system is running, the data required to be backed up during the current operation of the system is read, and the required backup data is stored in the shared memory. Monitor whether the state of the serial port pin changes to detect whether the power supply connected to the power input terminal of the computer device is powered off. When it is monitored that the state of the serial port pin changes and it is determined that the computer device is powered off, the required backup data stored in the shared memory is stored in the memory for backup. In this way, compared with the prior art, the present application realizes the detection of abnormal power failure by monitoring whether the state of the serial port pin changes without modifying the computer hardware, that is, without installing a power failure detection module, and when it is determined that the computer device is powered off, the required backup data stored in the shared memory is stored in the memory for backup, thereby reducing the risk of data loss and saving costs. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0040] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0041] Figure 1 A flowchart of the first embodiment of the power failure detection and data backup method of the present application is provided;
[0042] Figure 2 A flowchart of the second embodiment of the power failure detection and data backup method of the present application is provided;
[0043] Figure 3 A flowchart of the third embodiment of the power failure detection and data backup method of the present application is provided;
[0044] Figure 4 A brief flowchart diagram is provided for an exemplary embodiment of the power failure detection and data backup method of the present application.
[0045] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0046] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0047] It should be noted that all directional indications in the embodiments of the present application (such as up, down, left, right, front, back, etc.) are only used to explain the relative position relationship, movement status, etc. between the components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indication will also change accordingly.
[0048] In addition, the descriptions of "first", "second", etc. in this application are only for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in this field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such combination of technical solutions does not exist and is not within the scope of protection required by this application.
[0049] Technical terms involved in the embodiments of this application:
[0050] AES algorithm: AES (Advanced Encryption Standard) is a symmetric key encryption algorithm that uses the same key for encryption and decryption. AES has the advantages of high strength, high speed and easy implementation.
[0051] The AES encryption process consists of multiple steps, each of which performs a specific operation on the data. The following are the main steps of AES encryption:
[0052] Initial key plus: XOR the plaintext with the initial key.
[0053] Byte substitution (SubBytes): Use a fixed S-box (Substitution box) to replace each byte.
[0054] ShiftRows: Circularly shift each row of the state matrix to the left by a different number of bytes.
[0055] MixColumns: Perform a linear transformation on each column of the state matrix.
[0056] AddRoundKey: XOR the current state with the round key.
[0057] In the final round of encryption, no column obfuscation is performed.
[0058] The AES decryption process is the inverse of the encryption process and includes the following steps:
[0059] Reverse round key addition: XOR the ciphertext with the round key.
[0060] InvMixColumns: Perform an inverse linear transformation on each column of the state matrix.
[0061] InvShiftRows: Circularly shift each row of the state matrix right by a different number of bytes.
[0062] InvSubBytes: Substitute each byte using the inverse S-box.
[0063] In the final round of decryption, no reverse column obfuscation operation is performed.
[0064] SHA-256 algorithm: SHA-256 algorithm is a Secure Hash Algorithm 2, which can convert input data of any length into a fixed-length (256-bit) hash value. This process includes several key steps:
[0065] Initialization: At the beginning of the algorithm, 8 initial hash values are set, which are obtained based on the first 32 bits of the decimal part of the square roots of the first 8 prime numbers.
[0066] Preprocessing: The input data is first padded to bring its length to a certain standard that meets the algorithm requirements. After padding, a 64-bit length value is added to indicate the length of the original data.
[0067] Block processing: The processed data is divided into 512-bit blocks, and each block will be processed separately in the next steps.
[0068] Loop compression: 64 rounds of loop operations are performed on each data block. Operations include logical functions (such as AND, OR, XOR), addition, and bit rotation.
[0069] Generate the final hash value: After all data blocks are processed, the final hash value is composed of 8 hash values, which are the initial hash values modified after multiple rounds of operations.
[0070] The design of the SHA-256 algorithm ensures that the hash value it outputs has the following characteristics:
[0071] Deterministic: The same input always produces the same output hash value.
[0072] Irreversibility: The original input data cannot be deduced from the hash value.
[0073] Collision resistance: The probability of finding two different inputs that produce the same hash value is extremely low.
[0074] The existing technical solution proposes to install a power failure detection module on the device to monitor the power status and execute the shutdown procedure when detecting that the power is about to fail, so as to back up the data in time and ensure data security. However, this solution requires the installation of a power failure detection module, which leads to high costs.
[0075] The present application proposes a power failure detection and data backup method.
[0076] See also Figure 1 In the first embodiment of the present application, the power failure detection and data backup method is applied to a computer device, the serial port pin of the computer device is electrically connected to the power input terminal of the computer device, and the power failure detection and data backup method includes steps S10 to S40:
[0077] Step S10, in response to the power-on instruction, starting the backup process and creating a shared memory.
[0078] It should be noted that when the system is turned on, the backup process will be started and shared memory will be created. The shared memory will first read the important data that the user needs to back up. This memory can be accessed by other processes.
[0079] Step S20, when the system is running, reading the data that needs to be backed up when the system is currently running, and storing the data that needs to be backed up in the shared memory.
[0080] It should be noted that in an exemplary technical solution, by backing up a system, the entire operating system is copied when the system is turned on again after a power outage to ensure normal startup and operation of the system. Compared with the exemplary technical solution, the backed-up data in this embodiment is the data in the volatile memory, which may specifically include the status of the application currently running in the system, the data structure of the operating system kernel, the cached copies of the files and documents opened by the user, etc. The backed-up data is less, and the system starts and runs faster after the required backed-up data is restored again.
[0081] It should be noted that the serial port of the computer device includes a DSR (Data Set Ready) pin, which is usually used to indicate whether the remote device is ready for data communication. In this embodiment, the DSR pin is used to monitor whether the power supply connected to the power input terminal of the computer device is powered off.
[0082] It should be noted that the user program can modify the shared memory created in the backup process when the system is running, ensuring that the data in the shared memory is the latest data modified by the user. In this way, the present embodiment can capture the latest data status in time and save the important data to be backed up to the shared memory, thereby reducing the risk of data loss.
[0083] Step S30, monitoring whether the state of the serial port pin changes to detect whether the power supply connected to the power input terminal of the computer device is powered off.
[0084] It should be noted that the system has an event handling mechanism for serial port pin state changes, namely the PinChanged event. When the state of the DSR pin changes, the PinChanged event will be triggered, allowing the application to respond to this change and perform corresponding operations.
[0085] It should be noted that the system can detect the Pinchange event of the DSR pin of the serial port in real time in a blocking manner. If a Pinchange event occurs, it means that an abnormal power failure has occurred. If not, it will be blocked at this step of monitoring.
[0086] Step S40, when a change in the state of the serial port pin is detected and it is determined that the computer device is powered off, the data to be backed up stored in the shared memory is stored in the storage for backup.
[0087] It should be noted that the memory may specifically be a hard disk.
[0088] In a feasible implementation, when a change in the state of the serial port pin is detected and it is determined that the computer device has lost power, the data to be backed up stored in the shared memory can be stored in the storage device in sequence according to the preset backup priority for backup. Among the preset backup priorities, the backup priority of the system configuration file is the highest, and the backup priority of the configuration file of the running application is ranked from high to low according to the importance of the application. In this way, when the amount of data to be backed up is too large or in other extreme cases, even if the backup of all the data to be backed up cannot be guaranteed, the most important data can be backed up first, thereby minimizing the risk of damage to the system caused by power failure.
[0089] In another feasible implementation manner, after the step of monitoring a change in the state of the serial port pin and determining that the computer device is powered off, the method further includes:
[0090] The data to be backed up stored in the shared memory is sent to the server for backup.
[0091] It should be noted that the DSR pin of the serial port can be connected to the 12V power supply of the motherboard of the computer device. When the power is turned on, the DSR pin of the serial port is at a high level. When the motherboard loses power abnormally, the 12V power supply will immediately lose power and become a low level of 0V, so that the DSR pin of the serial port will also become a low level, which will trigger the Pinchange event of the serial port. After the trigger, the system will call the system callback function to start the action of backing up data, save the data stored in the shared memory to the storage for backup and / or upload it to the server for backup.
[0092] In another feasible implementation manner, after step S40, the power failure detection and data backup method further includes step S50:
[0093] Step S50, in response to the boot instruction, restoring the required backup data to the computer device.
[0094] It should be noted that the boot command can be manually input by the user or automatically generated by the computer device through a preset program before booting, and the boot command is used to trigger the system boot process. In this embodiment, when the system is re-triggered to start, the required backed-up data can be restored to the computer device, avoiding the situation where the device loses data due to an unexpected power outage, thereby failing to start or run normally.
[0095] In this embodiment, through steps S10 to S40, the power-off state of the computer device can be detected, and the data can be backed up in time when the power-off is detected. In this way, compared with the prior art, this embodiment realizes the detection of abnormal power failure by monitoring whether the state of the serial port pin changes or not without modifying the computer hardware, that is, without installing a power-off detection module, and when it is determined that the computer device has lost power, the data stored in the shared memory is stored in the storage for backup, which reduces the risk of data loss and saves costs. Moreover, the application backs up the data that needs to be backed up when the system is currently running, specifically the data in the volatile memory. Compared with backing up the files of the entire system, the amount of data backed up is smaller.
[0096] The main solution of the present application is: step S10, in response to the power-on instruction, start the backup process and create a shared memory. Step S20, when the system is running, read the data required to be backed up when the system is currently running, and store the required backup data in the shared memory. Step S30, monitor whether the state of the serial port pin changes to detect whether the power supply connected to the power input terminal of the computer device is powered off. Step S40, when the state of the serial port pin changes and it is determined that the computer device is powered off, the required backup data stored in the shared memory is stored in the memory for backup. In this way, compared with the prior art, the present application realizes the detection of abnormal power failure by monitoring whether the state of the serial port pin changes without modifying the computer hardware, that is, without installing the power failure detection module, and when it is determined that the computer device is powered off, the required backup data stored in the shared memory is stored in the memory for backup, reducing the risk of data loss and saving costs. Moreover, the present application backs up the data required to be backed up when the system is currently running, specifically the data in the volatile memory, and the amount of data backed up is smaller than that of backing up the files of the entire system.
[0097] See also Figure 2 Based on the first embodiment of the present application, in the second embodiment of the present application, the data to be backed up includes encrypted data. Before the step of storing the data to be backed up stored in the shared memory to the storage device for backing up, the power failure detection and data backup method further includes step S401:
[0098] Step S401: input the data to be backed up stored in the shared memory into a preset encryption algorithm for encryption to generate corresponding encrypted data.
[0099] In step S40, the step of storing the data to be backed up stored in the shared memory to the storage for backing up includes step S402:
[0100] Step S402: storing the encrypted data in the memory for backup.
[0101] After step S402, the power failure detection and data backup method further includes steps S501-S502:
[0102] Step S501, in response to a power-on instruction, input the encrypted data into a preset decryption algorithm corresponding to the preset encryption algorithm for decryption to obtain decrypted data.
[0103] Step S502: restoring the decrypted data to the computer device.
[0104] It should be noted that the preset encryption algorithm and the preset decryption algorithm corresponding to the preset encryption algorithm may specifically be an AES algorithm. AES is a symmetric encryption algorithm that uses the same key for encryption and decryption. AES has the advantages of high strength, high speed, and ease of implementation, and has high security and performance. In this way, the present embodiment can encrypt the data stored in the shared memory and then back it up, such as backing it up to the storage and / or server after encryption, and decrypting it when it is turned on again, which is beneficial to data security.
[0105] See also Figure 3 Based on the first embodiment of the present application, in the third embodiment of the present application, before the step of storing the required backup data stored in the shared memory to the storage device for backup, the power failure detection and data backup method further includes step S403:
[0106] Step S403: input the data to be backed up stored in the shared memory into a preset data summary algorithm to generate a corresponding first data summary.
[0107] The step of storing the required backup data stored in the shared memory to the storage device for backup includes step S404:
[0108] The data to be backed up and the first data summary stored in the shared memory are stored in the storage device for backup; wherein the first data summary is used to verify whether the data to be backed up is complete.
[0109] After step S404, the power failure detection and data backup method further includes steps S503 to S505:
[0110] Step S503, in response to the power-on instruction, obtaining the first backup data of the memory; wherein the first backup data includes the data to be backed up and the first data summary stored in the shared memory last time.
[0111] Step S504: input the data to be backed up in the first backup data into the preset data summary algorithm to generate a corresponding second data summary.
[0112] Step S505: when the first data digest successfully matches the second data digest, the required backup data in the first backup data is restored to the computer device.
[0113] It should be noted that the preset data digest algorithm can specifically be a SHA-256 algorithm. The SHA-256 algorithm is a type of Secure Hash Algorithm 2, which can convert input data of any length into a hash value of a fixed length (256 bits). In this embodiment, the SHA-256 algorithm can be used to generate a first data digest, and the first data digest is attached to the tail of the data to be backed up to ensure the integrity of the data. In this way, the present embodiment can generate a first data digest from the data stored in the shared memory and attach it to the tail of the data to be backed up and then back it up to the memory. When the computer is turned on again, the second data digest is generated again according to the data to be backed up in the first backup data, and the first data digest is matched and verified with the second data digest. When the match is successful, it means that the first backup data is accurate and complete, and the data to be backed up in the first backup data can be restored to the computer device. In this way, the present embodiment reduces the possibility of erroneous recovery of backup data.
[0114] It should be noted that before backing up the data, the AES algorithm can be used to encrypt the data to be backed up to obtain encrypted data, and the SHA-256 algorithm can be used to generate a first data digest for the encrypted data, and then the backup can be performed. Before restoring the backup data, the SHA-256 algorithm can be used to generate a second data digest, and a match check can be performed based on the first data digest and the second data digest. After the match is successful, the AES algorithm can be used to decrypt the data to be backed up, and the decrypted data can be restored to the computer device. In this way, the security of the backup data can be enhanced, and the risk of the system being unable to start due to incomplete or damaged backup data stored on the memory can be reduced.
[0115] In a feasible implementation manner, the data to be backed up stored in the shared memory is also sent to the server for backup. After the step of inputting the data to be backed up in the first backup data into the preset data summary algorithm to generate the corresponding second data summary, the power failure detection and data backup method further includes steps S506 to S508:
[0116] Step S506: when the first data digest fails to match the second data digest, obtain second backup data from the server; wherein the second backup data includes the required backup data stored in the shared memory at the last time the server backed up the data.
[0117] Step S507: input the second backup data into the preset data summary algorithm to generate a corresponding third data summary.
[0118] Step S508: When the first data digest successfully matches the third data digest, the second backup data is restored to the computer device.
[0119] In this embodiment, the data required for backup stored in the last shared memory of the memory backup is input into the SHA-256 algorithm to generate a corresponding second data digest. When the first data digest fails to match the second data digest, it means that the data on the memory is incomplete or damaged, and the data required for backup uploaded last time is obtained from the server. The second backup data is input into the SHA-256 algorithm to generate a corresponding third data digest, and is matched and verified with the first data digest. If the match is successful, it means that the data required for backup on the server is accurate and complete, and the second backup data can be restored to the computer device. In this way, this embodiment can read and restore complete data from the memory. When the data required for backup on the memory is incomplete, the second backup data is obtained from the server for data recovery, which enhances the robustness of system startup and operation and reduces the risk of the system being unable to start due to incomplete or damaged backup data stored on the memory.
[0120] Based on the first embodiment of the present application, in the fourth embodiment of the present application, in the power failure detection and data backup method, step S40 includes step S41:
[0121] Step S41, when a change in the state of the serial port pin is detected and it is determined that the computer device is powered off, the required backup data stored in the shared memory is stored in the storage device in a direct read-write manner of unbuffered I / O.
[0122] It should be noted that unbuffered I / O can realize instant writing of data, which is suitable for data backup of applications that need to immediately reflect data changes, such as data backup in real-time monitoring systems. In this embodiment, the data in the shared memory is backed up to the storage device in the form of unbuffered I / O, which is more efficient. Unbuffered I / O reduces the delay of data processing because it does not write the data to the buffer first and then to the storage device, which can improve the overall data processing efficiency. In addition, no additional buffer management is required, which can simplify the code and reduce development time. Backing up the data in the shared memory to the storage device in the form of unbuffered I / O is also beneficial to resource utilization, and the data can be directly written to the storage device, avoiding the memory resources that may be occupied due to buffer management.
[0123] Based on the first embodiment of the present application, in a fifth embodiment of the present application, the computer device includes a capacitor for supplying power when the computer device loses power. After step S40, the power-off detection and data backup method further includes step S42:
[0124] Step S42, in response to the data backup completion instruction stored in the shared memory, executing a shutdown instruction to shut down the computer device before the capacitor is completely discharged.
[0125] In this embodiment, after the data stored in the shared memory is backed up, the shutdown code can be executed to avoid damage to the system due to abnormal power failure and shutdown.
[0126] For example, to help understand the implementation process of the power failure detection and data backup method of the embodiment of the present application, please refer to Figure 4 , Figure 4 A brief flow chart of a power failure detection and data backup method is provided. Specifically, the steps of the power failure detection and data backup method include:
[0127] In response to the power-on command, the system boots up, starts the backup process, and creates a shared memory. The shared memory reads the important data that the user needs to back up, and this memory can be accessed by other processes. Among them, the user program can modify the shared memory created in the backup process while the system is running to ensure that the data in the shared memory is the latest data modified by the user.
[0128] The blocking mode detects the Pinchange event of the DSR pin of the serial port in real time. If a Pinchange event occurs, the state change of the serial port pin is monitored and the computer device is determined to be powered off. If no Pinchange event occurs, it will be blocked at this step.
[0129] If it is determined that the computer device is powered off, the data to be backed up in the shared memory is encrypted using the AES algorithm (Advanced Encryption Standard). The SHA-256 algorithm is used to generate a first data summary of the data to be backed up, and the first data summary is appended to the end of the data to verify the integrity of the data. It should be noted that AES encryption can be performed first, and then SHA-256 summary generation can be performed. The order of encryption and summary generation can also be adjusted according to the specific situation, and there is no limitation here.
[0130] The encrypted data corresponding to the data to be backed up and the first data summary are stored in the memory for backup in a direct read-write mode of unbuffered I / O, and the encrypted data corresponding to the data to be backed up is uploaded to a user-defined server for backup.
[0131] In response to the data backup completion instruction stored in the shared memory, a shutdown instruction is executed to avoid damage to the system due to abnormal power failure and shutdown.
[0132] In response to the power-on instruction, when the system is powered on again, the first backup data saved before power failure is obtained from the memory. The first backup data includes the encrypted data corresponding to the data to be backed up stored in the shared memory last time and the first data digest. The data to be backed up is decrypted by AES to obtain the decrypted data, and is input into the SHA-256 digest algorithm to obtain the corresponding second data digest. The first data digest is matched with the second data digest to verify the correctness and integrity of the first backup data. When the first data digest matches the second data digest successfully, it means that the data to be backed up on the memory is complete, and the data to be backed up is restored to the system.
[0133] When the first data digest fails to match the second data digest, it means that the data on the storage is incomplete or damaged, and the second backup data is obtained from the server. The second backup data includes the encrypted data corresponding to the data to be backed up stored in the shared memory last time the server backed up. The second backup data is decrypted by AES to obtain the decrypted data, and input into the SHA-256 digest algorithm to obtain the corresponding third data digest. When the first data digest successfully matches the third data digest, it means that the data to be backed up on the server is complete, and the data to be backed up is restored to the system.
[0134] In this way, the present embodiment monitors the occurrence of the Pinchange event of the DSR pin of the serial port in real time to detect power failure, and there is no need to add an additional power failure detection circuit for detection, thereby reducing costs. The required backup data is quickly backed up to the memory in a direct read and write manner of unbuffered I / O, and the backup efficiency is high. The use of the AES algorithm enhances the security of data backup, and the use of the SHA-256 digest algorithm has the function of verifying the integrity of the backup data. The present embodiment can obtain backup data from the memory or the server for data recovery, which enhances the robustness of system startup and operation.
[0135] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A power failure detection and data backup method, characterized in that: Applied to a computer device, the serial port pin of the computer device is electrically connected to the power input terminal of the computer device, and the computer device also includes a memory, and the method includes: In response to a power-on instruction, a backup process is started and a shared memory is created; When the system is running, the data required to be backed up when the system is currently running is read, and the data required to be backed up is stored in the shared memory; Monitoring whether the state of the serial port pin changes to detect whether the power supply connected to the power input terminal of the computer device is powered off; When a change in the state of the serial port pin is detected and it is determined that the computer device is powered off, the data to be backed up stored in the shared memory is stored in the storage for backup.
2. The power failure detection and data backup method according to claim 1, characterized in that: After the step of monitoring a change in the state of the serial port pin and determining that the computer device is powered off, the method further includes: The data to be backed up stored in the shared memory is sent to the server for backup.
3. The power failure detection and data backup method according to claim 1, characterized in that: After the step of storing the data to be backed up stored in the shared memory to the storage for backing up, the method further includes: In response to the boot instruction, the required backed-up data is restored to the computer device.
4. The power failure detection and data backup method according to claim 1, characterized in that: The data to be backed up includes encrypted data. Before the step of storing the data to be backed up stored in the shared memory to the storage for backing up, the method further includes: Inputting the data to be backed up stored in the shared memory into a preset encryption algorithm for encryption to generate corresponding encrypted data; The step of storing the required backup data stored in the shared memory to the storage device for backup comprises: The encrypted data is stored in the memory for backup.
5. The power failure detection and data backup method according to claim 4, characterized in that: After the step of storing the encrypted data in the memory for backup, the method further includes: In response to a power-on instruction, the encrypted data is input into a preset decryption algorithm corresponding to the preset encryption algorithm for decryption to obtain decrypted data; The decrypted data is restored to the computer device.
6. The power failure detection and data backup method according to claim 1, characterized in that: Before the step of storing the data to be backed up stored in the shared memory to the storage for backing up, the method further includes: Inputting the data to be backed up stored in the shared memory into a preset data summary algorithm to generate a corresponding first data summary; The step of storing the required backup data stored in the shared memory to the storage device for backup comprises: The data to be backed up and the first data summary stored in the shared memory are stored in the storage device for backup; wherein the first data summary is used to verify whether the data to be backed up is complete.
7. The power failure detection and data backup method according to claim 6, characterized in that: After the step of backing up the data to be backed up and the first data summary stored in the shared memory, the method further includes: In response to a power-on instruction, obtaining first backup data of the memory; wherein the first backup data includes the data to be backed up and the first data summary stored in the shared memory last time; Inputting the data to be backed up in the first backup data into the preset data summary algorithm to generate a corresponding second data summary; When the first data digest matches the second data digest successfully, the required backup data in the first backup data is restored to the computer device.
8. The power failure detection and data backup method according to claim 7, characterized in that: The data to be backed up stored in the shared memory is also sent to the server for backup; after the step of inputting the data to be backed up in the first backup data into the preset data summary algorithm to generate a corresponding second data summary, the method further includes: When the first data digest fails to match the second data digest, obtaining second backup data from the server; wherein the second backup data includes the required backup data stored in the shared memory last backed up by the server; Inputting the second backup data into the preset data summary algorithm to generate a corresponding third data summary; When the first data digest successfully matches the third data digest, the second backup data is restored to the computer device.
9. The power failure detection and data backup method according to claim 1, characterized in that: The step of storing the required backup data stored in the shared memory to the storage device for backup when a change in the state of the serial port pin is detected and the computer device is determined to be powered off comprises: When a change in the state of the serial port pin is detected and it is determined that the computer device is powered off, the required backup data stored in the shared memory is stored in the storage device in a direct read-write manner of an unbuffered I / O.
10. The power failure detection and data backup method according to claim 1, characterized in that: The computer device includes a capacitor for supplying power when the computer device is powered off. After the step of storing the required backup data stored in the shared memory to the storage for backup when a change in the state of the serial port pin is detected and the computer device is determined to be powered off, the method further includes: In response to the data backup completion instruction stored in the shared memory, a shutdown instruction is executed to shut down the computer device before the capacitor is fully discharged.