Data backup method and device, electronic equipment and readable storage medium
By copying the rewritten memory data to the backup memory before writing to disk, and using the backup memory as the data source when writing to disk, the Hibernation backup failure caused by insufficient free memory is solved, and the backup success rate is improved.
Patent Information
- Application Number
- CN202510686613.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-27
- Publication Date
- 2025-08-19
AI Technical Summary
In the prior art, Hibernation backups are prone to failure when the free memory is smaller than the used memory, resulting in the problem of backup failure.
Before detecting a write operation request for memory data, copy the data to be backed up to the backup memory. During the writing process to disk, use the backup memory as the data source to backup only the rewritten data to avoid backing up unrewritten data.
Reduces the amount of backup data, reduces the need for backup memory, and improves the success rate of Hibernation backups.
Smart Images

Figure CN120508450A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of data storage technology, and specifically relates to a data backup method, device, electronic device and readable storage medium. Background Art
[0002] With the rapid development of various electronic devices such as mobile phones, tablets, watches, computers, and car computers, users are more concerned about the system power consumption, power on and off speed, and whether the electronic devices can be restored to the state before shutdown.
[0003] In related technologies, hibernation technology can be used to save the current system's memory data image to a disk when the electronic device is turned off, and then shut down directly to save power consumption. When the device is turned on again, the snapshot data is read from the disk, and the memory, CPU, and peripheral status are restored accordingly, thereby ensuring that the operating environment after startup is consistent with that before shutdown.
[0004] However, the Hibernation backup technology in the related art requires that the static memory data at the snapshot time be completely backed up in the free memory before shutting down, and then the backup data in the free memory be written to the disk. This requires that the electronic device have sufficient free memory to complete the Hibernation backup. For example: the total memory size of the electronic device is 12GB. If the used memory still reaches 8GB after memory recycling, that is, the free memory is 4GB, then the 4GB free memory is not enough to back up the 8GB memory data, resulting in the failure of the Hibernation backup.
[0005] This shows that in the related art, when the free memory is smaller than the used memory, the Hibernation backup may fail. Summary of the Invention
[0006] The purpose of the embodiments of the present application is to provide a data backup method, device, electronic device and readable storage medium, which can improve the success rate of Hibernation backup.
[0007] In a first aspect, an embodiment of the present application provides a data backup method, the method comprising:
[0008] Determine the memory data to be backed up at the first moment;
[0009] When a write operation request for first data in the memory data to be backed up is detected, before performing the write operation, copying the first data to the backup memory;
[0010] In the process of writing the memory data to be backed up to the disk at the third moment, the backup memory is used as the data source of the first data, and the original memory of the second data is used as the data source of the second data; the second data is the data in the memory data to be backed up that has not been written between the first moment and the third moment.
[0011] In a second aspect, an embodiment of the present application provides a data backup device, the device comprising:
[0012] A determination module, configured to determine memory data to be backed up at a first moment;
[0013] a backup module configured to, upon detecting a write operation request for first data in the memory data to be backed up, copy the first data to a backup memory before executing the write operation;
[0014] A disk writing module is used to use the backup memory as the data source of the first data and the original memory of the second data as the data source of the second data during the process of writing the memory data to be backed up to the disk at a third moment; the second data is the data in the memory data to be backed up that has not been written between the first moment and the third moment.
[0015] In a third aspect, an embodiment of the present application provides an electronic device comprising a processor and a memory, wherein the memory stores programs or instructions that can be run on the processor, and when the programs or instructions are executed by the processor, the steps of the method described in the first aspect are implemented.
[0016] In a fourth aspect, an embodiment of the present application provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the steps of the method described in the first aspect are implemented.
[0017] In a fifth aspect, an embodiment of the present application provides a chip, which includes a processor and a communication interface, the communication interface and the processor are coupled, and the processor is used to run programs or instructions to implement the method described in the first aspect.
[0018] In a sixth aspect, an embodiment of the present application provides a computer program product, which is stored in a storage medium and executed by at least one processor to implement the method described in the first aspect.
[0019] In an embodiment of the present application, memory data to be backed up is determined at a first moment; when a write operation request for first data in the memory data to be backed up is detected, the first data is copied to a backup memory before performing the write operation; in the process of writing the memory data to be backed up to the disk at a third moment, the backup memory is used as the data source of the first data, and the original memory of the second data is used as the data source of the second data; the second data is the data in the memory data to be backed up on which no write operation is performed between the first moment and the third moment. After the memory data to be backed up is determined at the first moment, and before the memory data to be backed up is written to the disk at the third moment, if a write operation request for the first data occurs, the original first data before the rewrite is copied to the backup memory before the write operation is performed, and the original first data in the backup memory is subsequently written to the disk. For the second data on which no write operation is performed between the first moment and the third moment, there is no need to copy it to the backup memory. Instead, the original memory of the second data is used as the data source for writing the second data to the disk. In this way, only the backup memory needs to be used to back up the first data that has been rewritten, which can greatly reduce the amount of backup data, thereby reducing the memory size required for the backup memory. Even if the backup memory is smaller than the memory already in use, the memory data backup process can be successfully completed, thereby improving the success rate of Hibernation backup. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Figure 1 is a flow chart of a data backup method provided in some embodiments of the present application;
[0021] Figure 2 This is a flowchart of Hibernation backup data in the related art;
[0022] Figure 3 is a flowchart of Hibernation backup data in some embodiments of the present application;
[0023] Figure 4 is a structural diagram of a data backup device provided in some embodiments of the present application;
[0024] Figure 5 is a schematic structural diagram of an electronic device provided in some embodiments of the present application;
[0025] Figure 6 It is a schematic diagram of the hardware structure of the electronic device provided in some embodiments of the present application. DETAILED DESCRIPTION
[0026] The following will be combined with the accompanying drawings in the embodiments of the present application to clearly describe the technical solutions in the embodiments of the present application. Obviously, the embodiments described are 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 are within the scope of protection of this application.
[0027] The terms "first," "second," and the like in the specification and claims of this application are used to distinguish similar objects, and are not used to describe a specific order or precedence. It should be understood that the terms used in this manner are interchangeable where appropriate, so that the embodiments of this application can be implemented in an order other than that illustrated or described herein, and that the objects distinguished by "first," "second," and the like are generally of the same type, and do not limit the number of objects; for example, the first object can be one or more. In addition, the term "and / or" in the specification and claims refers to at least one of the connected objects, and the character " / " generally indicates that the objects connected are in an "or" relationship.
[0028] The data backup method, data backup device, electronic device, and storage medium provided in the embodiments of the present application are described in detail below with reference to specific embodiments and their application scenarios in conjunction with the accompanying drawings.
[0029] See Figure 1 The data backup method provided in the embodiment of the present application includes the following steps:
[0030] Step 101: Determine memory data to be backed up at a first moment.
[0031] In some embodiments, the first moment may be the moment when the memory data is triggered to be backed up, for example: writing the memory data to the disk before the electronic device is shut down, and after starting up, restoring the operating environment before shutdown based on the data in the disk. At this time, the first moment may be the moment when the shutdown event is triggered, such as the moment when the user's shutdown operation is received.
[0032] In some embodiments, the memory data to be backed up may include the memory data of all processes of the electronic device executing the data backup method of the embodiment of the present application at the first moment, the central processing unit (CPU), status information of external devices, etc.
[0033] Step 102: When a write operation request for first data in the memory data to be backed up is detected, the first data is copied to the backup memory before the write operation is performed.
[0034] Step 103: During the process of writing the memory data to be backed up to the disk at the third moment, the backup memory is used as the data source of the first data, and the original memory of the second data is used as the data source of the second data; the second data is the data in the memory data to be backed up that has not been written between the first moment and the third moment.
[0035] It should be noted that the process of writing the memory data to be backed up to the disk takes a period of time. At this time, the third moment is the moment when each data or each data unit, such as a data page, in the memory data to be backed up is written to the disk.
[0036] In some embodiments, when a write operation request for the first data in the memory data to be backed up is detected, the first data is copied to the backup memory before the write operation is performed. Alternatively, when a write operation request for the first data in the memory data to be backed up is detected at a second moment, the first data is copied to the backup memory before the write operation is performed, wherein the second moment is any moment after the first moment and before the third moment when the first data is written to the disk.
[0037] For example, assuming the memory data to be backed up includes data on data pages 1 through 100, the third moment includes the moment when each of data pages 1 through 100 is written to disk. For one data page n, before writing data page n to disk, a determination is made as to whether backup data for that data page n exists in the backup memory. If so, this indicates that data page n is the data page containing the first data, and thus the backup data page n in the backup memory is used as the data source for writing to disk. If no backup data for data page n exists in the backup memory, this indicates that data page n is second data that was created after the first moment and was not written to disk before being written to disk, and thus the original memory is used as the data source for writing data page n to disk.
[0038] It should be noted that the memory data to be backed up is static data, that is, snapshot data at the first moment. However, the process of writing the memory data to be backed up to the disk takes a certain amount of time. During this time, the operating system corresponding to the memory data is still in running state. As the operating system runs, the memory data to be backed up may be accessed, that is, the memory data to be backed up may be rewritten within this time.
[0039] In the related art, in order to write the snapshot data at the same moment to the disk, it is necessary to first copy all the memory data to be backed up at the first moment to the idle backup memory, and then write the snapshot data in the backup memory to the disk. In this way, even if the data to be backed up in the original memory is rewritten, it will not affect the snapshot data stored in the backup memory, thereby realizing the writing of the snapshot data in the backup memory to the disk. In other words, in the related art, it is necessary to back up all the used memory space at the first moment once, and then write the snapshot data in the backup memory to the disk. This process needs to meet the requirement that the size of the backup memory in the idle state is greater than or equal to the size of the memory used at the first moment. For example, assuming that the total memory size of the electronic device is 12GB, if the used memory still reaches 8GB after memory recycling, that is, the idle memory is 4GB, then the 4GB of idle memory is not enough to back up the 8GB of memory data, resulting in the failure of the Hibernation backup.
[0040] In the embodiment of the present application, the memory data to be backed up is divided into two types: one is the first data that has been written to between the first moment and the third moment; the other is the second data that has not been written to between the first moment and the third moment.
[0041] That is, a write operation occurs for the first data at the second moment, and therefore, the original first data in the memory before the second moment is different from the new first data in the memory after the second moment, wherein the memory data to be backed up at the first moment includes the original first data. In an embodiment of the present application, by copying the original first data in the memory to the backup memory before rewriting the original first data into the new first data, even if the original first data in the memory is rewritten into the new first data, the memory data to be backed up at the first moment can still be obtained based on the original first data backed up in the backup memory and the second data in the memory data to be backed up that has not been written.
[0042] It is worth mentioning that the first data that is rewritten within the disk write time after the first moment only occupies a very small memory space compared to the entire memory data to be backed up. For example: assuming that the total memory size of the electronic device is 12GB, if the used memory reaches 8GB after memory recycling, that is, the free memory is 4GB, in the process of writing 8GB of memory data to the disk, only a few B or KB of data may be rewritten. In this way, you only need to back up these few B or KB of data to the backup memory before rewriting. The 4GB of free memory is completely sufficient to back up these few B or KB of memory data.
[0043] In some embodiments, when writing memory data to be backed up to disk, the number of first data that is overwritten may be one or more. In this case, for each first data, the original first data before overwriting is backed up to the backup memory.
[0044] Different from the method in the related art of first backing up all static data and then writing the static data in the backup memory to the disk, in the embodiment of the present application, during the process of writing the static data to be backed up to the disk, the backup data in the backup memory is dynamically updated following the write operation of the static data to be backed up, and the backup data in the backup memory is combined with the original data in the original memory to realize the complete disk writing of the static data.
[0045] For example: assuming that the memory data to be backed up includes the data in data page 1 to data page 100, at this time, starting from the first moment of determining the memory data to be backed up, data page 1, data page 2, ..., data page 100 can be written to the disk in the order of data page 1 to data page 100. If a write operation request for the data in data page 2 is detected before writing data page 2, the data in data page 2 is copied to the backup memory for backup before the write operation is performed on the data in data page 2, and then the write operation is performed on the data in the original memory of data page 2. In this way, when the third moment of writing data page 2 to disk is reached, it can be detected that the data exists in the backup memory. The backup data of data page 2 is written to the disk with the backup content as the data source of data page 2; thereafter, if a write operation request for the data in data page 50 is detected before writing data page 50, the data in data page 50 is copied to the backup memory for backup before the write operation is performed on the data in data page 50, and then the write operation is performed on the data in the original memory of data page 50. In this way, when the third moment of writing data page 50 to the disk is reached, it can be detected that there is backup data of data page 50 in the backup memory, so that the backup content is written to the disk as the data source of data page 50; and the cycle is repeated until all data pages 1 to 100 are written to the disk.
[0046] In some embodiments, in the process of writing the memory data to be backed up to the disk at the third moment, the backup memory is used as the data source of the first data, and the original memory of the second data is used as the data source of the second data, including: writing the data in each data page in the memory data to be backed up to the disk one by one. In this process, it can be detected whether the current data in the data page that needs to be written to the disk at the third moment has backup data in the backup memory; if so, the backup data of the current data in the backup memory is written to the disk; if not, the original data of the current data in the memory is written to the disk.
[0047] In some embodiments, when copying the first data to the backup memory, first tag information corresponding to the first data can be created. When writing the memory data to be backed up to the disk at the third moment, the backup memory is used as the data source of the first data, and the original memory of the second data is used as the data source of the second data. This includes: when writing the memory data to be backed up to the disk at the third moment, detecting whether the target data to be written has the first tag information; if so, writing the backup target data in the backup memory to the disk; if not, writing the target data in the memory to the disk. The target data is the first data or the second data.
[0048] In an embodiment of the present application, memory data to be backed up is determined at a first moment; when a write operation request for first data in the memory data to be backed up is detected, the first data is copied to a backup memory before performing the write operation; in the process of writing the memory data to be backed up to the disk at a third moment, the backup memory is used as the data source of the first data, and the original memory of the second data is used as the data source of the second data; the second data is the data in the memory data to be backed up on which no write operation is performed between the first moment and the third moment. After the memory data to be backed up is determined at the first moment, and before the memory data to be backed up is written to the disk at the third moment, if a write operation request for the first data occurs, the original first data before the rewrite is copied to the backup memory before the write operation is performed, and the original first data in the backup memory is subsequently written to the disk. For the second data on which no write operation is performed between the first moment and the third moment, there is no need to copy it to the backup memory. Instead, the original memory of the second data is used as the data source for writing the second data to the disk. In this way, only the backup memory needs to be used to back up the first data that has been rewritten, which can greatly reduce the amount of backup data, thereby reducing the memory size required for the backup memory. Even if the backup memory is smaller than the memory already in use, the memory data backup process can be successfully completed, thereby improving the success rate of Hibernation backup.
[0049] As an optional implementation, the method further includes:
[0050] Creating first marking information for the data page where the first data is located;
[0051] The step of using the backup memory as the data source of the first data and the original memory of the second data as the data source of the second data includes:
[0052] If it is detected that the data page where the target data is located has first marking information, the backup data page of the backup memory is used as the data source of the target data;
[0053] If it is detected that the data page where the target data is located does not have the first marking information, then using the original data page of the original memory where the target data is located as the data source of the target data;
[0054] The target data is the first data or the second data.
[0055] In some embodiments, when a write operation to the first data is detected at the second moment, first marking information can be created for the data page containing the first data. This first marking information can indicate that backup data exists for the corresponding data page in the backup memory. In this way, when the data in each data page of the memory data to be backed up is subsequently written to the disk in units of data pages, the data page currently to be written to the disk can be detected to determine whether it has the corresponding first marking information. If the first marking information exists, the data source of the data page is replaced with the backup data page in the backup memory, thereby enabling the backup data page in the backup memory to be written to the disk.
[0056] In some embodiments, when all the data in a data page is second data that has not been rewritten, the data page does not have the first mark information, so that the first mark information will not be detected during the process of writing the data page to the disk. Accordingly, the original data page in the data memory is used as the data source of the data page to achieve the writing of the original data page in the data memory to the disk.
[0057] In some implementations, the first marking information may explicitly or implicitly indicate a corresponding data page.
[0058] For example, a bit map of data pages may be generated, the bit map including an indication bit for each data page included in the memory data to be backed up, wherein if the indication bit of a data page is equal to "1", it indicates that a backup data page exists for the data page in the backup memory, i.e., the first indication information of the data page includes an indication bit in the bit map that is equal to "1" and corresponds to the data page; if the indication bit of a data page is equal to "0", it indicates that a backup data page does not exist for the data page in the backup memory.
[0059] Optionally, when it is necessary to write data in a certain data page to the disk, the indicator bit of the data page can be searched based on the bit map. If the indicator bit is "1", the corresponding backup data page is searched from the backup memory, such as searching for a backup data page with the same data page number as the data page to be written, and writing the backup data page to the disk as the data source of the data page.
[0060] Of course, the first marking information may also be other information, such as a character string containing the page number of the corresponding data page, etc. The first marking information is not specifically limited here.
[0061] In this embodiment, based on the first marking information, the data pages containing the data that has been rewritten while waiting to be written to the disk can be marked. Therefore, in the process of writing the data pages in the memory data to be backed up to the disk one by one, it is possible to determine which data pages need to use the backup data pages in the backup memory as the data source and which data pages can directly use the original data pages in the memory as the data source based on the first marking information, thereby simplifying the process of determining the data source of the data pages to be written to the disk.
[0062] In some implementations, for multiple data in the same data page, one or at least two data may be rewritten. In this case, only one first mark information may be created for the same data page.
[0063] As an optional implementation manner, before creating the first marking information for the data page where the first data is located, the method further includes:
[0064] Detecting whether first marking information exists on the data page where the first data is located;
[0065] The step of creating first marking information for the data page where the first data is located includes:
[0066] If the data page where the first data is located does not contain the first mark information, the first mark information is created for the data page where the first data is located.
[0067] For example: assuming that a data page includes first sub-data and second sub-data, before the third time the data page is written to the disk, the first tag information of the data page is created based on the first sub-data being accessed and overwritten. Thereafter, if the second sub-data is also accessed and overwritten before the third time the data page is written to the disk, it can be detected that the first tag information already exists on the data page, and the first tag information is no longer created repeatedly.
[0068] In this embodiment, only one piece of first marking information is generated for the same data page, which can avoid repeated creation of the first marking information and improve the utilization rate of the first marking information.
[0069] As an optional implementation manner, determining the memory data to be backed up at the first moment includes:
[0070] Determine memory data to be backed up at a first moment, and create second marking information, where the second marking information is global information;
[0071] The step of, upon detecting a write operation request for first data in the memory data to be backed up, copying the first data to the backup memory before performing the write operation, comprises:
[0072] When the second marking information is detected and a write operation request for the first data in the memory data to be backed up is detected, the first data is copied to the backup memory before the write operation is performed.
[0073] In some embodiments, the second marker information is used to mark a memory data backup event. After the memory data backup event is complete, the second marker information can be deleted. Alternatively, the second marker information can be deleted after the system operating environment is restored based on the snapshot data on the disk. In this way, the second marker information can be re-created when the memory data backup event is subsequently triggered.
[0074] For example, the second marking information may be a global parameter hib_snapshot equal to "1", wherein when the global parameter hib_snapshot is equal to "0", it indicates that the second marking information does not exist or the second marking information is cleared.
[0075] In this embodiment, when a memory data backup event is triggered, the static data that currently needs to be backed up can be determined, and second marking information can be created to mark the need to back up the memory data to the disk based on the second marking information. In this way, only when the second marking information is detected and the first data is overwritten, the copying of the first data before the overwrite to the backup memory is triggered. In other words, if the memory data backup event is not triggered, the second marking information will not be generated. In this case, even if the first data is overwritten, the first data before the overwrite will not be copied to the backup memory. In this way, the amount of backup memory occupied can be reduced.
[0076] As an optional implementation, the method further includes:
[0077] Execute shutdown operation at the fourth moment;
[0078] During the boot process, restoring the operating environment at the first moment based on the backup memory data in the disk;
[0079] The first marking information and / or the second marking information is eliminated.
[0080] In some embodiments, the fourth moment can be any moment after all the memory data to be backed up is written to the disk, or the fourth moment is the same as the last third moment in the process of writing the memory data to be backed up to the disk, that is, the computer is shut down immediately after all the memory data to be backed up is written to the disk.
[0081] In some embodiments, restoring the operating environment at the first moment based on the backup memory data in the disk may include restoring the process, CPU status, external device status, etc. at the first moment based on the backup memory data in the disk.
[0082] In some embodiments, when the first marking information is created, after the operating environment at the first moment is restored based on the backup memory data in the disk, the first marking information is eliminated, for example: all indicator bits in the bit map of the data page are set to "0", or the bit map of the data page is deleted.
[0083] In this way, when the memory data backup event is triggered next time, corresponding first marking information can be created according to the actual situation of the data rewritten in the memory data backup event, thereby avoiding confusion between the first marking information of different memory data backup events.
[0084] In some embodiments, when the second marking information is created, after the operating environment at the first moment is restored based on the backup memory data in the disk, the second marking information is eliminated, for example: the second marking information is deleted, or the global parameter hib_snapshot is set to "0".
[0085] In this way, the second marking information can be recreated when the memory data backup event is triggered next time, thereby avoiding retaining the second marking information of the completed memory data backup event when the memory data backup event is not triggered, thereby causing unnecessary data backup.
[0086] In order to facilitate understanding of the data backup method of the embodiment of the present application, the Hibernation backup technology of the data backup method of the embodiment of the present application is compared with the Hibernation backup technology in the related art as an example. Figure 2 As shown, the Hibernation backup technology in the related art includes the following steps:
[0087] Step 201, Sync Fs: refresh part of the data in the memory to the disk, at least ensuring that the latest data in the cache has been refreshed to the disk;
[0088] Step 202: Freeze Processes: Freeze all processes in the system.
[0089] Step 203, Save Devices: Save the status information of all peripherals to the memory;
[0090] Step 204: Create Snapshot: Create snapshot information of the current system memory data;
[0091] This step 204 may specifically include the following sub-steps:
[0092] Sub-step 2041, Count pages: determine which data pages need to be saved and count the number;
[0093] Sub-step 2042, Alloc pages: allocate the required backup memory from the free memory, the backup memory is mainly used to back up data;
[0094] Sub-step 2043, Copy data: copy all data pages that need to be saved to the backup memory;
[0095] Sub-step 2044, Copy meta data: The so-called meta data is the location of the page, that is, all backed-up pages.
[0096] Step 205: Save Snapshot: compress the snapshot information and write it to disk.
[0097] This step 205 may specifically include the following sub-steps:
[0098] Sub-step 2051, Write header: write the snapshot-related header information to the disk;
[0099] Sub-step 2052, Compress data: copy the snapshot image to the backup memory and compress it;
[0100] Sub-step 2053, Write data: write the compressed image data to the disk.
[0101] Step 206, Power Off: Finally shut down the device.
[0102] After completing a Hibernation backup, the process of restoring the system operating environment based on the snapshot data on the disk includes:
[0103] Step 207: Power On: power on;
[0104] Step 208, Read Snapshot: re-read the snapshot from the disk into the memory;
[0105] Step 209: Restore Snapshot: overwrite the current system with the snapshot data to restore the scene;
[0106] Step 210: Restore Devices: Restore the previously saved device status.
[0107] Step 211, Thaw Processes: Thaw all processes and restore the state before shutdown, so that the original system can continue to run.
[0108] Through Figure 2 As can be seen from the process of the Hibernation backup technology shown, the related technology needs to allocate a backup memory that can store all the memory data to be backed up, so that the memory data to be backed up is first backed up to the backup memory for compression, and then the compressed memory data to be backed up in the backup memory is written to the disk.
[0109] like Figure 3 As shown, the Hibernation backup technology of the data backup method according to the embodiment of the present application includes the following steps:
[0110] Step 301, Sync Fs: refresh some data in the memory to the disk to ensure that the latest data in the cache has been refreshed to the disk;
[0111] Step 302: Freeze Processes: Freeze all processes in the system.
[0112] Step 303: Save Devices: save the status information of all peripherals to the memory;
[0113] Step 304: Create Snapshot: Create snapshot information of the current system memory data;
[0114] This step 304 may specifically include the following sub-steps:
[0115] Sub-step 3041, Count pages: determine which data pages need to be saved and count the number;
[0116] Sub-step 3042, Mark hib: Create a second marker. The second marker is used to indicate that the system is in the hibernation data backup process. That is, from the moment this second marker is created, all subsequent memory write operations must first back up the original memory data.
[0117] Step 3042 may be implemented based on the following pseudo code:
[0118] 1.unsigned int hib_snapshot=0;
[0119] 2.alloc_pages;
[0120] copy_data;
[0121] --->hib_snapshot=1;
[0122] hib_snapshot defines a global variable for marking whether the current Hibernation process has entered the backup snapshot phase; then, hib_snapshot=1 is used to generate second marking information to replace the alloc_pages and copy_data steps in the related art.
[0123] Sub-step 3043, Page rewrite: indicates executing a write operation on the first data;
[0124] Sub-step 3044, Set page flag: indicating creating first marking information for the data page where the first data is located;
[0125] Sub-step 3045, Copy data: indicates copying the data page where the first data is located to the backup memory;
[0126] Sub-step 3046, Copy meta data: The so-called meta data is the location of the page, that is, all backed-up pages.
[0127] Sub-step 3047, Set bitmap: indicates this bitmap, recording the first marking information.
[0128] The above sub-steps 3043 to 3046 can be implemented by embedding corresponding memory access logic in the Hibernation process. The memory access logic can be implemented based on the following pseudo code:
[0129] 1.if(write memory){
[0130] 2.if(hib_snapshot==1&&check_page_flag(page)!=1){
[0131] 3.set_page_flag(page);
[0132] 4.copy_data(new_page,page);
[0133] 5.set_bitmap(copy_bm);
[0134] 6.}
[0135] The logic of the above pseudocode is as follows:
[0136] Detect write operations. When writing data to a certain memory address, the dirty page flag will be set. If hib_snapshot is 1, it means that the system is currently preparing to make a memory snapshot image, and uses check_page_flag to check whether the first flag information of the data page targeted by the write operation is set. If it is set, no further processing will be performed. Otherwise, the first flag information, i.e., page_flag, is set for the data page. When the memory data of the same data page is subsequently written, the setting of page_flag of the same data page is skipped. This page_flag will be cleared when the system operating environment is restored. For the data page where the first data is rewritten, a new page new_page is allocated in the backup memory and the data in the original page is saved to this new page. Then, the data in the current page is marked as modified in the bitmap of the backup image, and the data in new_page is used when the data in the page is written to disk.
[0137] This step 305, Save Snapshot: compress the snapshot information and write it to disk;
[0138] This step 305 may specifically include the following sub-steps:
[0139] Sub-step 3051, Write header: write the snapshot-related header information to the disk;
[0140] Sub-step 3052, Compress data: copy the snapshot image to the backup memory and compress it;
[0141] Sub-step 3053, Check bitmap: Check all bits of the bitmap to determine which data pages need to use the data in the new_page in the backup memory;
[0142] Sub-step 3054, Replace data: Use the new_page in the backup memory corresponding to the bit corresponding to the first mark information as the data required to save the snapshot, and copy it to buff as the source of subsequent disk compression data;
[0143] Sub-step 3055, Write data: write the compressed image data to the disk.
[0144] The above sub-steps 3053 to 3055 can be implemented based on the following pseudo code:
[0145] 1.if(check_bitmap(copy_bm)){
[0146] 2.replace_data(new_page,buff);
[0147] 3.}
[0148] The logic of the above pseudocode is as follows:
[0149] Check which pages in the copy_bm bitmap have their corresponding bits set to 1. If they are set to 1, the contents of these pages have been overwritten. Use the new_page in the backup memory corresponding to the bit corresponding to the first flag information as the data required to save the snapshot, and copy it to buff as the source of subsequent disk compression data.
[0150] Step 306: Power Off: Finally shut down the device.
[0151] After completing a Hibernation backup, the process of restoring the system operating environment based on the snapshot data on the disk includes:
[0152] Step 307: Power On: power on;
[0153] Step 308: Read Snapshot: re-read the snapshot from the disk into the memory;
[0154] Step 309: Restore Snapshot: overwrite the current system with the snapshot data to restore the scene;
[0155] Step 310: Clear bitmap: clear the bitmap;
[0156] Step 311: Clear page flag: clear the first flag information;
[0157] Step 312: Clear hib: clear the second mark information;
[0158] The above steps 310 to 312 can be implemented by embedding the following pseudo code in the Hibernation restore process:
[0159] 1.clear_bitmap(copy_bm);
[0160] 2.clear_page_flag(page);
[0161] 3.hib_snapshot = 0;
[0162] The logic of the above pseudocode is as follows:
[0163] Clear the bitmap corresponding to the previously overwritten page, clear the page flag of the corresponding page, that is, the first flag information, and reset the value of the hib_snapshot global variable to 0. At this time, the system is restored to the state before Hibernation.
[0164] Step 313: Restore Devices: Restore the previously saved device status.
[0165] Step 314, Thaw Processes: Thaw all processes and restore the state before shutdown, so that the original system can continue to run.
[0166] As can be seen from the above process, when the Hibernation backup technology of the data backup method of the embodiment of the present application is applied, when entering the Hibernation process, it is necessary to first synchronize the file system related data in the current memory to the disk; then freeze other tasks in the current system and retain only the task that is currently completing Hibernation; save the status of all devices in the current system so that they can be restored to the current status after restarting later; the process of making mirror snapshot data only marks that it is currently in the Hibernation process, that is, creates the second mark information. With the second mark information, any subsequent access to memory data requires copying the original data to the backup memory; when writing the mirror snapshot data to the disk, if it is found that the original data page has a backup in the backup memory, it needs to be replaced with the backed-up data and then written to the disk; finally, when the system is restored, all marks, that is, the first mark information, the second mark information and the bit map of the data page are restored to the system's initial running state.
[0167] The Hibernation backup technology of the data backup method according to the embodiment of the present application no longer pre-allocates backup memory capable of backing up all snapshot data during the Hibernation snapshot backup process. Instead, backup memory is dynamically allocated when the data before being overwritten needs to be copied. Since most of the data does not need to be backed up, the size of the allocated backup memory can be greatly reduced, the data copying time is reduced, and the success rate of Hibernation is improved.
[0168] The data backup method provided in the embodiment of the present application can be executed by a data backup device. In the embodiment of the present application, the data backup device provided in the embodiment of the present application is described by taking the data backup method executed by the data backup device as an example.
[0169] See Figure 4 The data backup device 400 provided in this embodiment of the present application includes the following modules:
[0170] A determination module 401 is configured to determine memory data to be backed up at a first moment;
[0171] The backup module 402 is configured to, upon detecting a write operation request for first data in the memory data to be backed up, copy the first data to a backup memory before performing the write operation;
[0172] The disk writing module 403 is used to use the backup memory as the data source of the first data and the original memory of the second data as the data source of the second data during the process of writing the memory data to be backed up to the disk at the third moment; the second data is the data in the memory data to be backed up that has not been written between the first moment and the third moment.
[0173] In some implementations, the data backup device 400 further includes:
[0174] a marking module, configured to create first marking information for the data page where the first data is located;
[0175] The disk writing module 403 includes:
[0176] a first determining unit, configured to use the backup data page of the backup memory as a data source of the target data if it is detected that the data page where the target data is located has first marking information;
[0177] a second determining unit, configured to use the original data page of the original memory where the target data is located as the data source of the target data if it is detected that the data page where the target data is located does not have the first marking information;
[0178] The target data is the first data or the second data.
[0179] In some implementations, the data backup device 400 further includes:
[0180] A detection module, configured to detect whether the data page where the first data is located has first marking information;
[0181] The marking module is configured to create the first marking information for the data page where the first data is located when the detection module detects that the data page where the first data is located does not have the first marking information.
[0182] In some implementations, the determination module 401 includes:
[0183] a marking unit, configured to determine memory data to be backed up at a first moment and create second marking information, where the second marking information is global information;
[0184] an acquiring unit, configured to acquire the memory data to be backed up at the first moment;
[0185] The backup module 402 is specifically configured to:
[0186] When the second marking information is detected and a write operation request for the first data in the memory data to be backed up is detected, the first data is copied to the backup memory before the write operation is performed.
[0187] In some implementations, the data backup device 400 further includes:
[0188] An execution module, configured to execute a shutdown operation at a fourth moment;
[0189] A recovery module, configured to restore the operating environment at the first moment based on the backup memory data in the disk during the boot process;
[0190] The elimination module is configured to eliminate the first marking information and / or the second marking information.
[0191] The data backup device 400 in the embodiment of the present application can be an electronic device or a component in an electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal or other device other than a terminal. For example, the electronic device can be a mobile phone, a tablet computer, a laptop computer, a PDA, an in-vehicle electronic device, a mobile internet device (MID), an augmented reality (AR) / virtual reality (VR) device, a robot, a wearable device, an ultra-mobile personal computer (UMPC), a netbook or a personal digital assistant (PDA), etc. It can also be a server, a network attached storage (NAS), a personal computer (PC), a television (TV), a teller machine or a self-service machine, etc., and the embodiment of the present application does not specifically limit it.
[0192] The data backup device 400 in the embodiment of the present application may be a device having an operating system. The operating system may be an Android operating system, an iOS operating system, or other possible operating systems, which are not specifically limited in the embodiment of the present application.
[0193] The data backup device 400 provided in this embodiment of the present application can achieve Figure 1 or Figure 3 The various processes implemented by the method embodiment shown can achieve the same beneficial effects as the aforementioned data backup method embodiment of this application. To avoid repetition, they will not be described here.
[0194] Alternatively, as Figure 5 As shown, an embodiment of the present application also provides an electronic device 500, including a processor 501 and a memory 502, wherein the memory 502 stores a program or instruction that can be run on the processor 501, and when the program or instruction is executed by the processor 501, the various steps of the above-mentioned data backup method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0195] It should be noted that the electronic devices in the embodiments of the present application include the mobile electronic devices and non-mobile electronic devices mentioned above.
[0196] Figure 6 A schematic diagram of the hardware structure of an electronic device implementing an embodiment of the present application.
[0197] The electronic device 600 includes but is not limited to components such as a radio frequency unit 601 , a network module 602 , an audio output unit 603 , an input unit 604 , a sensor 605 , a display unit 606 , a user input unit 607 , an interface unit 608 , a memory 609 , and a processor 610 .
[0198] Those skilled in the art will understand that the electronic device 600 may also include a power source (such as a battery) to power each component, and the power source may be logically connected to the processor 610 through a power management system, thereby implementing functions such as charging, discharging, and power consumption management through the power management system. Figure 6 The electronic device structure shown in the figure does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently, which will not be repeated here.
[0199] The processor 610 is configured to determine memory data to be backed up at a first moment;
[0200] The processor 610 is further configured to, upon detecting a write operation request for first data in the memory data to be backed up, control the memory 609 to copy the first data to the backup memory before performing the write operation;
[0201] The processor 610 is also used to control the memory 609 to write the memory data to be backed up to the disk at the third moment, using the backup memory as the data source of the first data and the original memory of the second data as the data source of the second data; the second data is the data in the memory data to be backed up that has not been written between the first moment and the third moment.
[0202] In some implementations, the processor 610 is further configured to create first marking information for the data page where the first data is located;
[0203] The processor 610 performs the step of using the backup memory as the data source of the first data and using the original memory of the second data as the data source of the second data, including:
[0204] If it is detected that the data page where the target data is located has first marking information, the backup data page of the backup memory is used as the data source of the target data;
[0205] If it is detected that the data page where the target data is located does not have the first marking information, then using the original data page of the original memory where the target data is located as the data source of the target data;
[0206] The target data is the first data or the second data.
[0207] In some embodiments, the processor 610 is further used to detect whether the data page where the first data is located has first tag information; and when the detection module detects that the data page where the first data is located does not have the first tag information, create the first tag information for the data page where the first data is located.
[0208] In some implementations, the determining of memory data to be backed up at the first moment performed by the processor 610 includes:
[0209] Determine memory data to be backed up at a first moment, and create second marking information, where the second marking information is global information;
[0210] Obtaining memory data to be backed up at the first moment;
[0211] The processor 610 controls the memory 609 to copy the first data to the backup memory before performing the write operation when a write operation request for the first data in the memory data to be backed up is detected, including:
[0212] When the second marking information is detected and a write operation request for the first data in the memory data to be backed up is detected, the control memory 609 copies the first data to the backup memory before executing the write operation.
[0213] In some implementations, the processor 610 is further configured to execute a shutdown operation at a fourth moment;
[0214] The processor 610 is further configured to restore the operating environment at the first moment based on the backup memory data in the disk during the boot process;
[0215] The processor 610 is further configured to eliminate the first marking information and / or the second marking information.
[0216] The electronic device according to the embodiment of the present application can achieve the following Figure 4 The functions implemented by each module in the data backup device shown can achieve the same beneficial effects, so they will not be described here to avoid repetition.
[0217] It should be understood that in an embodiment of the present application, the input unit 604 may include a graphics processing unit (GPU) 6041 and a microphone 6042, and the graphics processor 6041 processes the image data of a static picture or video obtained by an image capture device (such as a camera) in a video capture mode or an image capture mode. The display unit 606 may include a display panel 6061, and the display panel 6061 may be configured in the form of a liquid crystal display, an organic light emitting diode, etc. The user input unit 607 includes a touch panel 6071 and at least one of other input devices 6072. The touch panel 6071 is also called a touch screen. The touch panel 6071 may include two parts: a touch detection device and a touch controller. Other input devices 6072 may include, but are not limited to, a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, and a joystick, which will not be repeated here.
[0218] The memory 609 can be used to store software programs and various data. The memory 609 may mainly include a first storage area for storing programs or instructions and a second storage area for storing data, wherein the first storage area may store an operating system, applications or instructions required for at least one function (such as a sound playback function, an image playback function, etc.). In addition, the memory 609 may include a volatile memory or a non-volatile memory, or the memory 609 may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), a static random access memory (SRAM), a dynamic random access memory (DRAM), a synchronous dynamic random access memory (SDRAM), a double data rate synchronous dynamic random access memory (DDRSDRAM), an enhanced synchronous dynamic random access memory (ESDRAM), a synchronous link dynamic random access memory (SLDRAM), and a direct memory bus random access memory (DRRAM). The memory 609 in the embodiment of the present application includes but is not limited to these and any other suitable types of memory.
[0219] Processor 610 may include one or more processing units. Optionally, processor 610 integrates an application processor and a modem processor. The application processor primarily handles operations related to the operating system, user interface, and application programs, while the modem processor primarily processes wireless communication signals, such as a baseband processor. It is understood that the modem processor may not be integrated into processor 610.
[0220] An embodiment of the present application also provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the various processes of the above-mentioned data backup method embodiment are implemented and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0221] The processor is the processor in the electronic device described in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0222] An embodiment of the present application further provides a chip, which includes a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run programs or instructions to implement the various processes of the above-mentioned data backup method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0223] It should be understood that the chip mentioned in the embodiments of the present application can also be called a system-level chip, a system chip, a chip system or a system-on-chip chip, etc.
[0224] An embodiment of the present application provides a computer program product, which is stored in a storage medium. The program product is executed by at least one processor to implement the various processes of the above-mentioned data backup method embodiment and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0225] It should be noted that, in this article, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device comprising the element. In addition, it should be noted that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in the opposite order according to the functions involved. For example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.
[0226] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus the necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a computer software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), including a number of instructions for enabling a terminal (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0227] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of this application, ordinary technicians in this field can also make many forms without departing from the purpose of this application and the scope of protection of the claims, all of which are within the protection of this application.
Claims
1. A data backup method, characterized in that: include: Determine the memory data to be backed up at the first moment; When a write operation request for first data in the memory data to be backed up is detected, before performing the write operation, copying the first data to the backup memory; In the process of writing the memory data to be backed up to the disk at the third moment, the backup memory is used as the data source of the first data, and the original memory of the second data is used as the data source of the second data; The second data is data in the memory data to be backed up that has not been written to between the first moment and the third moment.
2. The method according to claim 1, characterized in that The method further comprises: Creating first marking information for the data page where the first data is located; The step of using the backup memory as the data source of the first data and the original memory of the second data as the data source of the second data includes: If it is detected that the data page where the target data is located has first marking information, the backup data page of the backup memory is used as the data source of the target data; If it is detected that the data page where the target data is located does not have the first marking information, then using the original data page of the original memory where the target data is located as the data source of the target data; The target data is the first data or the second data.
3. The method according to claim 2, characterized in that Before creating first marking information for the data page where the first data is located, the method further includes: Detecting whether first marking information exists on the data page where the first data is located; The step of creating first marking information for the data page where the first data is located includes: If the data page where the first data is located does not contain the first mark information, the first mark information is created for the data page where the first data is located.
4. The method according to claim 1, characterized in that The determining of the memory data to be backed up at the first moment includes: Determine memory data to be backed up at a first moment, and create second marking information, where the second marking information is global information; The step of, upon detecting a write operation request for first data in the memory data to be backed up, copying the first data to the backup memory before performing the write operation, comprises: When the second marking information is detected and a write operation request for the first data in the memory data to be backed up is detected, the first data is copied to the backup memory before the write operation is performed.
5. The method according to any one of claims 2 to 4, characterized in that The method further comprises: Execute shutdown operation at the fourth moment; During the boot process, restoring the operating environment at the first moment based on the backup memory data in the disk; The first marking information and / or the second marking information is eliminated.
6. A data backup device, characterized in that: include: A determination module, configured to determine memory data to be backed up at a first moment; a backup module configured to, upon detecting a write operation request for first data in the memory data to be backed up, copy the first data to a backup memory before executing the write operation; a disk writing module, configured to use the backup memory as a data source of the first data and the original memory of the second data as a data source of the second data during a process of writing the memory data to be backed up to the disk at a third moment; The second data is data in the memory data to be backed up that has not been written to between the first moment and the third moment.
7. The device according to claim 6, characterized in that The device further comprises: a marking module, configured to create first marking information for the data page where the first data is located; The disk writing module includes: a first determining unit, configured to use the backup data page of the backup memory as a data source of the target data if it is detected that the data page where the target data is located has first marking information; a second determining unit, configured to use the original data page of the original memory where the target data is located as the data source of the target data if it is detected that the data page where the target data is located does not have the first marking information; The target data is the first data or the second data.
8. The device according to claim 7, characterized in that The device further comprises: A detection module, configured to detect whether the data page where the first data is located has first marking information; The marking module is configured to create the first marking information for the data page where the first data is located when the detection module detects that the data page where the first data is located does not have the first marking information.
9. The device according to claim 6, characterized in that The determining module includes: a marking unit, configured to determine memory data to be backed up at a first moment and create second marking information, where the second marking information is global information; an acquiring unit, configured to acquire the memory data to be backed up at the first moment; The backup module is specifically used to: When the second marking information is detected and a write operation request for the first data in the memory data to be backed up is detected, the first data is copied to the backup memory before the write operation is performed.
10. The device according to any one of claims 7 to 9, characterized in that The device further comprises: An execution module, configured to execute a shutdown operation at a fourth moment; A recovery module, configured to restore the operating environment at the first moment based on the backup memory data in the disk during the boot process; The elimination module is configured to eliminate the first marking information and / or the second marking information.
11. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores programs or instructions that can be run on the processor, and when the programs or instructions are executed by the processor, the steps of the data backup method according to any one of claims 1 to 5 are implemented.
12. A readable storage medium, characterized in that: The readable storage medium stores a program or instruction, and when the program or instruction is executed by a processor, the steps of the data backup method according to any one of claims 1 to 5 are implemented.