Backup method and device, electronic equipment and storage medium
By monitoring and suspending target operations based on the operating system kernel in the computer system, the target objects are backed up, and the problem of large backup operation overhead in the existing technology is solved, and a more efficient backup process is achieved.
Patent Information
- Application Number
- CN202411893448.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-20
- Publication Date
- 2025-03-25
AI Technical Summary
The initial runtime and storage space cost of file backup operations in existing computer systems is relatively large, especially when there are more directories and files being monitored, the greater the overhead.
By monitoring the target operation based on the operating system kernel, and suspending the target operation before it is executed, the target object targeted by the target operation is backed up, obtaining the backup object, and then performing the target operation.
It effectively reduces the initial runtime overhead and storage space overhead of backup operations, and only performs backups when needed, avoiding the overhead of backing up all files and directories.
Smart Images

Figure CN119690752A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a backup method, device, electronic equipment and storage medium. Background Art
[0002] At present, the file backup of computer systems is usually carried out in the following way: first specify the directories and files to be monitored; then perform a static full backup of the monitored directories and files; then perform a differential backup of the monitored directories and files, that is, back up the data that has changed since the last backup. Among them, since the static full backup requires a complete backup of the monitored directories and files, the initialization running time overhead and storage space overhead of the backup operation are very large. The more directories and files are monitored, the greater the overhead. Summary of the invention
[0003] In view of this, embodiments of the present invention provide a backup method, device, electronic device and storage medium, which can solve the problems of large initialization runtime overhead and large storage space overhead of backup operations.
[0004] In a first aspect, an embodiment of the present invention provides a backup method, comprising: monitoring a target operation based on a virtual file system of an operating system kernel, and suspending the target operation before the target operation is executed; backing up a target object targeted by the target operation to obtain a backup object, wherein the target object includes a target file and / or a target directory; and executing the target operation on the target object.
[0005] In one embodiment, the virtual file system based on the operating system kernel monitors the target operation and suspends the target operation before the target operation is executed, including: based on a hook function pre-set at the application interface of the target operation in the virtual file system, monitoring the target operation and suspending the target operation before the target operation is executed; backing up the target object targeted by the target operation to obtain the backup object includes: in the hook function, backing up the target object targeted by the target operation to obtain the backup object.
[0006] In one embodiment, the hook function pre-set at the application interface of the target operation based on the virtual file system monitors the target operation and suspends the target operation before the target operation is executed, including: when the target operation is called based on the application interface, obtaining operation-related information of the target operation through the hook function and suspending the target operation, wherein the operation-related information includes: an identifier of the initiator of the target operation, a storage path of the target object targeted by the target operation, and metadata of the target object; in the hook function, backing up the target object targeted by the target operation to obtain the backup object includes: in the hook function, backing up the target object based on the operation-related information to obtain the backup object.
[0007] In one embodiment, in the hook function, the target object is backed up based on the operation association information, and obtaining the backup object includes: determining whether the initiator of the target operation is an associated process of a preset application according to the identifier of the initiator of the target operation, and the associated process of the preset application includes the process of the preset application and / or the sub-process of the process; in response to the initiator of the target operation being the associated process of the preset application, determining whether the target object targeted by the target operation is a monitoring object according to the storage path of the target object targeted by the target operation; in response to the target object being the monitoring object, backing up the target object to obtain the backup object.
[0008] In one embodiment, in response to the target object being the monitored object, backing up the target object to obtain the backup object includes: determining whether the target object has not been backed up based on the metadata of the target object; and in response to the target object not being backed up, backing up the target object to obtain the backup object.
[0009] In one embodiment, after determining whether the initiator of the target operation is an associated process of a preset application based on the identifier of the initiator of the target operation, the method further includes: refusing to back up the target object in response to the initiator of the target operation not being an associated process of the preset application.
[0010] In one embodiment, after determining whether the target object targeted by the target operation is a monitoring object based on the storage path of the target object targeted by the target operation, the method further includes: refusing to back up the target object in response to the target object not being the monitoring object.
[0011] In one implementation, the number of initiators of the target operation is at least one.
[0012] In one implementation, the metadata includes at least one of the following: object type, object operation permission, object owner, object size, object access information, and data block location of a file-type object.
[0013] In one embodiment, the method further includes: setting the hook function at the application program interface of the target operation in the virtual file system based on the hook function pre-set at the application program interface of the target operation in the virtual file system, monitoring the target operation and suspending the target operation before the target operation is executed.
[0014] In one implementation, backing up the target object targeted by the target operation to obtain the backup object includes: backing up the target object targeted by the target operation to obtain the backup object, and recording an operation log of the target operation.
[0015] In one implementation, the operation log includes: the operation type of the target operation, the target object targeted by the target operation, and the storage path of the backup object of the target object.
[0016] In one implementation, the operation type of the target operation includes at least one of the following: creating a new object, modifying object content, deleting an object, renaming an object, and creating an object link.
[0017] In one embodiment, after performing the target operation on the target object, the method further includes: in response to a preset instruction or in response to an execution error of the target operation, restoring the target object to the backup object according to the operation log and the backup object of the target object.
[0018] In one embodiment, the operation log includes at least one log entry, wherein each log entry has a corresponding backup object; restoring the target object to the backup object based on the operation log and the backup object of the target object includes: performing a recovery operation on the target object in reverse order of the recording time of each log entry in the operation log, using the backup object corresponding to each log entry in sequence, until the target object is restored to the backup object corresponding to a preset log entry.
[0019] In one implementation, the preset log entry includes a log entry recorded for the first time in the operation log corresponding to the target object.
[0020] In one implementation, after restoring the target object to the backup object according to the operation log and the backup object of the target object, the method further includes: deleting the restored backup object and the operation log corresponding to the backup object.
[0021] In one embodiment, after backing up the target object targeted by the target operation, obtaining the backup object, and recording the operation log of the target operation, the method further includes: deleting the backup object and the operation log in response to an instruction to exit monitoring.
[0022] In a second aspect, an embodiment of the present invention further provides a backup device, comprising: a monitoring unit, used to monitor a target operation based on a virtual file system of an operating system kernel, and suspend the target operation before the target operation is executed; a backup unit, used to back up a target object targeted by the target operation to obtain a backup object, wherein the target object includes a target file and / or a target directory; and an execution unit, used to execute the target operation on the target object.
[0023] In one embodiment, the monitoring unit is specifically used to monitor the target operation and suspend the target operation before the target operation is executed based on a hook function pre-set at the application interface of the target operation in the virtual file system; the backup unit is specifically used to back up the target object targeted by the target operation in the hook function to obtain the backup object.
[0024] In one embodiment, the monitoring unit is specifically used to obtain operation-related information of the target operation through the hook function and suspend the target operation when the target operation is called based on the application program interface, wherein the operation-related information includes: an identifier of the initiator of the target operation, a storage path of the target object targeted by the target operation, and metadata of the target object; the backup unit is specifically used to back up the target object based on the operation-related information in the hook function to obtain the backup object.
[0025] In one embodiment, the backup unit includes: a first determination module, used to determine whether the initiator of the target operation is an associated process of a preset application based on the identifier of the initiator of the target operation, and the associated process of the preset application includes the process of the preset application and / or the sub-process of the process; a second determination module, used to determine whether the target object targeted by the target operation is a monitoring object based on the storage path of the target object targeted by the target operation in response to the initiator of the target operation being the associated process of the preset application; a backup module, used to back up the target object in response to the target object being the monitoring object to obtain the backup object.
[0026] In one implementation, the backup module is specifically configured to: determine whether the target object has not been backed up based on the metadata of the target object; and in response to the target object not being backed up, back up the target object to obtain the backup object.
[0027] In one embodiment, the backup unit also includes: a first rejection module, which is used to determine whether the initiator of the target operation is an associated process of a preset application based on the identifier of the initiator of the target operation, and then refuse to back up the target object in response to the initiator of the target operation not being an associated process of the preset application.
[0028] In one embodiment, the backup unit also includes: a second rejection module, which is used to determine whether the target object targeted by the target operation is a monitored object based on the storage path of the target object targeted by the target operation, and in response to the target object not being the monitored object, refuse to back up the target object.
[0029] In one implementation, the number of initiators of the target operation is at least one.
[0030] In one implementation, the metadata includes at least one of the following: object type, object operation permission, object owner, object size, object access information, and data block location of a file-type object.
[0031] In one embodiment, the device also includes a setting unit for setting the hook function at the application program interface of the target operation in the virtual file system based on a hook function pre-set at the application program interface of the target operation in the virtual file system, monitoring the target operation and suspending the target operation before the target operation is executed, and setting the hook function at the application program interface of the target operation in the virtual file system through the virtual machine running in the operating system kernel.
[0032] In one implementation, the backup unit is specifically configured to back up the target object targeted by the target operation, obtain the backup object, and record an operation log of the target operation.
[0033] In one implementation, the operation log includes: the operation type of the target operation, the target object targeted by the target operation, and the storage path of the backup object of the target object.
[0034] In one implementation, the operation type of the target operation includes at least one of the following: creating a new object, modifying object content, deleting an object, renaming an object, and creating an object link.
[0035] In one embodiment, the device also includes a recovery unit for restoring the target object to the backup object based on the operation log and the backup object of the target object in response to a preset instruction or in response to an execution error of the target operation after performing the target operation on the target object.
[0036] In one embodiment, the operation log includes at least one log entry, wherein each log entry has a corresponding backup object; the recovery unit is specifically used to perform recovery operations on the target object in reverse order of the recording time of each log entry in the operation log, using the backup objects corresponding to each log entry in sequence, until the target object is restored to the backup object corresponding to the preset log entry.
[0037] In one implementation, the preset log entry includes a log entry recorded for the first time in the operation log corresponding to the target object.
[0038] In one embodiment, the device further includes a first deleting unit for deleting the restored backup object and the operation log corresponding to the backup object after restoring the target object to the backup object based on the operation log and the backup object of the target object.
[0039] In one embodiment, the device also includes a second deletion unit, which is used to delete the backup object and the operation log in response to an instruction to exit monitoring after backing up the target object targeted by the target operation, obtaining the backup object, and recording the operation log of the target operation.
[0040] In a third aspect, an embodiment of the present invention further provides an electronic device, comprising: a housing, a processor, a memory, a circuit board and a power supply circuit, wherein the circuit board is placed inside the space enclosed by the housing, and the processor and the memory are arranged on the circuit board; a power supply circuit for supplying power to various circuits or devices of the above-mentioned electronic device; the memory is used to store executable program code; the processor runs a program corresponding to the executable program code by reading the executable program code stored in the memory, so as to execute the backup method provided in any embodiment of the present invention.
[0041] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the backup method provided by any embodiment of the present invention.
[0042] The backup method, device, electronic device and storage medium provided by the embodiments of the present invention can monitor the target operation based on the virtual file system of the operating system kernel, suspend the target operation before the target operation is executed, back up the target object targeted by the target operation, and obtain the backup object, wherein the target object includes the target file and / or the target directory, and the target operation is performed on the target object. In this way, it is only necessary to monitor the target operation and back up the target object before the target object is processed by the target operation. If the target operation is not monitored, there is no need to perform the corresponding backup, instead of backing up all the monitored files and directories as in the related art. Therefore, the initialization running time overhead and storage space overhead of the backup operation can be effectively reduced. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the embodiments of the present invention 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, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0044] Figure 1 A flow chart of a backup method provided by an embodiment of the present invention; Figure 2 Another flow chart of a backup method provided by an embodiment of the present invention; Figure 3 Another flow chart of the backup method provided by the embodiment of the present invention; Figure 4 A schematic diagram of the structure of a backup device provided by an embodiment of the present invention; Figure 5A schematic structural diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0045] The embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0046] It should be clear that the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0047] In a first aspect, an embodiment of the present invention provides a backup method that can effectively reduce the initialization runtime overhead and storage space overhead of a backup operation.
[0048] like Figure 1 As shown, an embodiment of the present invention provides a backup method, including: S11, monitoring a target operation based on a virtual file system of an operating system kernel, and suspending the target operation before the target operation is executed; The virtual file system is an abstract layer in the operating system kernel that provides a unified file and directory operation interface for user space applications. The virtual file system allows different file system types (such as ext4 (Fourthextended file system), NFS (Network File System), etc.) to coexist in the operating system, and makes the upper-layer applications not need to care about the specific implementation details of the underlying file system. Among them, the operating system can include, for example, Linux system, Unix system and its derivative systems.
[0049] In the embodiment of the present invention, the target operation may be various operations for files and / or directories. In this step, after the target operation is detected, the target operation may be suspended before the target operation is executed, and the execution of the target operation may be suspended.
[0050] S12, backing up the target object targeted by the target operation to obtain a backup object, wherein the target object includes a target file and / or a target directory; After the target operation is suspended, in this step, the target object targeted by the target operation can be backed up to obtain a backup object. Here, backup can refer to saving a copy. The target object can refer to the operation object of the target operation, and the target object can include both the target file (such as file1) and the target directory (such as / HOME / demo / my list).
[0051] S13: Execute the target operation on the target object.
[0052] After the target object is backed up, in this step, the previously suspended target operation can be resumed, thereby executing the corresponding target operation on the target object.
[0053] The backup method provided by the embodiment of the present invention can monitor the target operation based on the virtual file system of the operating system kernel, suspend the target operation before the target operation is executed, back up the target object targeted by the target operation, and obtain the backup object, wherein the target object includes the target file and / or the target directory, and the target operation is executed on the target object. In this way, it is only necessary to monitor the target operation and back up the target object before the target object is processed by the target operation. If the target operation is not monitored, there is no need to perform the corresponding backup, instead of backing up all the monitored files and directories as in the related art. Therefore, the initialization running time overhead and storage space overhead of the backup operation can be effectively reduced.
[0054] In addition, the backup method provided by the embodiment of the present invention has no restriction on the number of monitored files and directories, and the monitored files and directories can be reasonably set as needed, thus greatly expanding the scope of application.
[0055] It should be noted that in the embodiments of the present invention, the type, quantity and occurrence timing of the target operation are not limited, and each time the target operation occurs, the target operation can be monitored and suspended, and the corresponding target object can be backed up.
[0056] Specifically, in the embodiment of the present invention, the target operation may include multiple operation types, such as creating a new object, modifying object content, deleting an object, renaming an object, creating an object link, etc. In step S11, these target operations may be monitored and suspended before the target operation is executed.
[0057] In one embodiment of the present invention, step S11 monitors the target operation based on the virtual file system of the operating system kernel, and suspends the target operation before the target operation is executed, which may include: based on the hook function (hook function) pre-set at the application program interface of the target operation in the virtual file system, monitoring the target operation and suspending the target operation before the target operation is executed. Based on this, backing up the target object targeted by the target operation in step S12 to obtain the backup object may include: backing up the target object targeted by the target operation in the hook function to obtain the backup object. In this way, whenever the target operation calls the corresponding application program interface, the target operation can be suspended, the hook function is executed first, and the target operation is executed after the hook function is executed. Based on this, in the hook function, the target object targeted by the target operation is backed up, and the target object can be backed up before the target object is processed by the target operation to obtain the corresponding backup object.
[0058] In one embodiment of the present invention, in order to obtain the hook function, based on the hook function pre-set at the application program interface of the target operation in the virtual file system, monitor the target operation and suspend the target operation before the target operation is executed, the backup method provided by the embodiment of the present invention may also include: setting the hook function at the application program interface of the target operation in the virtual file system through the virtual machine running in the operating system kernel. The virtual machine may include, for example, eBPF (extended Berkeley Packet Filter).
[0059] In a specific implementation, based on the hook function pre-set at the application program interface of the target operation in the virtual file system, monitoring the target operation and suspending the target operation before the target operation is executed may include: when the target operation is called based on the application program interface, obtaining the operation-related information of the target operation through the hook function and suspending the target operation, wherein the operation-related information may include: the identifier of the initiator of the target operation, the storage path of the target object targeted by the target operation, and the metadata of the target object. Based on this, in the hook function, backing up the target object targeted by the target operation and obtaining the backup object may specifically include: in the hook function, backing up the target object based on the operation-related information and obtaining the backup object.
[0060] In this embodiment, the operation-related information may refer to information associated with the target operation. The initiator of the target operation may refer to which application initiated the target operation, for example, the office word application initiated the target operation of modifying a file. In one embodiment of the present invention, the number of initiators of the target operation may be one, and in another embodiment of the present invention, the number of initiators of the target operation may also be multiple, which is not limited in the embodiment of the present invention.
[0061] The metadata of a target object may refer to a set of data used to describe the characteristics of the target object. In one embodiment of the present invention, the metadata may include at least one of the following: object type, object operation permission, object owner, object size, object access information, and data block location of a file-type object. Among them, the object type may be, for example, a file, a directory, a symbolic link, etc.; the object operation permission may include, for example, read permission, write permission, execute permission, etc.; the object access information may include, for example, creation time, last modification time, last access time, etc.
[0062] In one embodiment, in the hook function, backing up the target object based on the operation association information, and obtaining the backup object may include: determining whether the initiator of the target operation is an associated process of a preset application according to the identifier of the initiator of the target operation, and the associated process of the preset application includes the process of the preset application and / or the sub-process of the process; in response to the initiator of the target operation being the associated process of the preset application, determining whether the target object targeted by the target operation is a monitoring object according to the storage path of the target object targeted by the target operation; in response to the target object being the monitoring object, backing up the target object to obtain the backup object.
[0063] In this embodiment, the preset application may be a preset application that needs to monitor the operation of the file. The associated process may include the process corresponding to the preset application, and may also include the sub-process of the process. For example, in one example, the preset applications may include: Software Manager, Word, WeChat, etc. Then, if the initiator of the target operation is the process or sub-process of these applications, it is possible to further determine whether the target object targeted by the target operation is a monitoring object based on the storage path of the target object targeted by the target operation. In a specific implementation, the storage path of the target object can be compared with the preset storage path. If the two are consistent, it can be determined that the target object is a monitoring object. If the two are inconsistent, it can be determined that the target object is not a monitoring object. Among them, the storage path of the target object is consistent with the preset storage path, which can include that the storage path of the target object is the same as the preset storage path, or the storage path of the target object is under the preset storage path. Exemplarily, in one example, the preset storage path is / HOME / test / river, if the storage path of the target object is also / HOME / test / river, it can be determined that the target object is a monitoring object; if the storage path of the target object is / HOME / class, and it is different from the preset storage path, it can be determined that the target object is not a monitored object.
[0064] In one embodiment of the present invention, in response to the target object being the monitored object, backing up the target object, and obtaining the backup object may specifically include: determining whether the target object has not been backed up according to the metadata of the target object; in response to the target object not being backed up, backing up the target object to obtain the backup object. In this embodiment, metadata can be used to characterize the characteristics of the target object. If the target object has been operated, the metadata corresponding to the target object will also be different. Therefore, in an embodiment of the present invention, the corresponding target object can be determined according to the metadata, thereby determining whether the target object has not been backed up. For example, if the metadata of a backup object A among the existing backup objects is the same as the metadata of the target object, it means that the target object has not been backed up, and there is no need to back it up again. If the metadata of each backup object among the existing backup objects is different from the metadata of the target object, it means that the target object has not been backed up, and the target object can be backed up.
[0065] The above embodiments illustrate the case where the initiator of the target operation is an associated process of a preset application and the target object is a monitoring object, but the embodiments of the present invention are not limited thereto. In other embodiments of the present invention, the initiator of the target operation may not be an associated process of a preset application, or the target object may not be a monitoring object.
[0066] To this end, in one embodiment of the present invention, after determining whether the initiator of the target operation is an associated process of a preset application according to the identifier of the initiator of the target operation, the backup method provided by the embodiment of the present invention may also include: in response to the initiator of the target operation not being an associated process of the preset application, refusing to back up the target object. In other words, when the initiator of the target operation is not an associated process of the preset application, it means that the target operation is initiated by other processes. In order not to affect the operation of other processes, there is no need to suspend the target process or back up the corresponding target object.
[0067] Similarly, in another embodiment of the present invention, after determining whether the target object targeted by the target operation is a monitored object based on the storage path of the target object targeted by the target operation, the backup method provided by the embodiment of the present invention may also include: refusing to back up the target object in response to the target object not being the monitored object.
[0068] In the aforementioned embodiment, the target object targeted by the target operation can be backed up, but the embodiments of the present invention are not limited thereto. In other embodiments of the present invention, a corresponding operation log can also be recorded. For example, in one embodiment of the present invention, backing up the target object targeted by the target operation and obtaining the backup object can include: backing up the target object targeted by the target operation, obtaining the backup object, and recording the operation log of the target operation. The operation log can include operation information related to the backup operation. For example, in one example, the operation log can include: the operation type of the target operation, the target object targeted by the target operation, and the storage path of the backup object of the target object.
[0069] Optionally, in one embodiment of the present invention, the operation type of the target operation may include at least one of the following: creating a new object, modifying the content of an object, deleting an object, renaming an object, and creating an object link. The operation type of the target operation is different, and the situation of the backup object may also be different. For example, if the operation type of the target operation is creating a new object, since the corresponding object does not exist before, there is no need to back up, or the backup object is empty. If the operation type of the target operation is modifying the content of an object, the target object before modification can be backed up to obtain a backup object.
[0070] Based on this, after performing the target operation on the target object in step S13, the backup method provided by the embodiment of the present invention may further include: in response to a preset instruction or in response to an execution error of the target operation, restoring the target object to the backup object according to the operation log and the backup object of the target object. In some cases, the target operation performed on the target object may have an error, or, in other cases, it is desired to restore the target object to a previous version. For this reason, in the embodiment of the present invention, the target object may be restored to the corresponding backup object.
[0071] In a specific implementation, when restoring the target object using the backup object, the reverse operation of the backup operation can be used. For example, in one example, the operation type of the target operation recorded in the operation log is to create a new object. When restoring, it is only necessary to delete the newly created object. In another example, the operation type of the target operation recorded in the operation log is to modify the object content or delete the object. When restoring, it is only necessary to replace the target object with the backup object. Specifically, the backup object can be copied to the original path. In another example, the operation type of the target operation recorded in the operation log is to rename the object. In this case, the object name can be restored.
[0072] Specifically, in one embodiment of the present invention, the operation log may include at least one log entry, wherein each log entry has a corresponding backup object; depending on the operation type of the target operation in the log entry, the backup object may include specific content or may be empty. Based on this, according to the operation log and the backup object of the target object, restoring the target object to the backup object may specifically include: in the reverse order of the recording time of each log entry in the operation log, using the backup objects corresponding to each log entry in sequence, performing a recovery operation on the target object until the target object is restored to the backup object corresponding to the preset log entry. The preset log entry may be any log entry in the operation log. For example, in one example, the preset log entry may include the log entry recorded for the first time in the operation log corresponding to the target object.
[0073] For example, in one embodiment of the present invention, the operation log may include three records, log entry 1, log entry 2, and log entry 3, in the order of the log entry recording time from earliest to latest. Log entry 1 corresponds to backup object 1, log entry 2 corresponds to backup object 2, and log entry 3 corresponds to backup object 3. If the preset log entry is log entry 1, when restoring, the target object may be restored to backup object 3 first, then backup object 3 may be restored to backup object 2, and finally backup object 2 may be restored to backup object 1. If the preset log entry is log entry 2, when restoring, the target object may be restored to backup object 3 first, then backup object 3 may be restored to backup object 2.
[0074] Furthermore, in an embodiment of the present invention, after restoring the target object to the backup object according to the operation log and the backup object of the target object, the backup method provided by the embodiment of the present invention may further include: deleting the restored backup object and the operation log corresponding to the backup object. Since the backup object has been restored, deleting the backup object and the corresponding operation log can release the corresponding storage space, effectively improving the storage space utilization.
[0075] Furthermore, in another embodiment of the present invention, after backing up the target object targeted by the target operation, obtaining the backup object, and recording the operation log of the target operation, the backup method provided by the embodiment of the present invention may also include: in response to an instruction to exit monitoring, deleting the backup object and the operation log. In other words, if an instruction to stop monitoring is received, the backup object and the corresponding log entry may also be deleted, thereby releasing the corresponding storage space and effectively improving the storage space utilization rate.
[0076] Exemplarily, the backup method provided by the embodiment of the present invention can be as follows: Figure 2 As shown in the figure, the target object is specifically a target file.
[0077] The backup method provided by the embodiment of the present invention can be used in various application scenarios.
[0078] For example, it can be applied in the scenario of system OTA (Over The Air) rollback. There are two main problems when the system OTA is performed: (1) The target file of OTA is any file in the entire disk, so a large number of files need to be monitored; (2) During OTA, scripts are usually run to dynamically modify some files. These dynamically modified files are not known when the OTA package is made. Therefore, when the OTA does not meet expectations, if you want to roll back to the previous system, these dynamically modified files may not be able to roll back to the previous state. After adopting the backup method of the present invention, for problem (1), the technical solution provided by the embodiment of the present invention does not limit the number of monitored files and directories. For problem (2), since running the script is a subprocess of the upgrade program, the dynamically modified files will be backed up and the operation log will be recorded during the upgrade, so that the backup file and operation log can be used to roll back to the previous state.
[0079] For another example, it can be applied in the scenario where the package manager performs a deep uninstall of software. Software installation usually consists of two parts, one part is static files, and the package manager can clearly know which files are installed; the other part is dynamically modified files, which are files modified by running scripts during installation. The package manager cannot know which software has been modified, so when the software is uninstalled, the dynamically modified files may not be uninstalled. Through the technical solution provided by the embodiment of the present invention, since the scripts running during installation belong to the subprocess of the package manager, the modified files can be monitored and backed up, so the package manager can restore these files to the state before installation when uninstalling.
[0080] For another example, it can be applied in the scenario of backup management during software operation. After the monitoring solution is started during the software operation, the files modified during the software operation can also be monitored, recorded and backed up by the solution, so that the recovery operation can be performed at any time.
[0081] The backup method provided by the embodiment of the present invention is described in detail below through specific embodiments.
[0082] like Figure 3 As shown, the backup method provided by the embodiment of the present invention may include: S201. Setting a hook function at an application program interface of a target operation in a virtual file system through a virtual machine running in an operating system kernel.
[0083] S202: When the target operation is called based on the application program interface, the operation association information of the target operation is obtained through the hook function and the target operation is suspended.
[0084] The operation-related information may include: an identifier of the initiator of the target operation, a storage path of a target object targeted by the target operation, and metadata of the target object.
[0085] S203. Determine, based on the identifier of the initiator of the target operation, whether the initiator of the target operation is an associated process of a preset application; if so, execute step S204; if not, execute step S211.
[0086] The associated process of the preset application may include the process of the preset application and / or a sub-process of the process; S204. Determine whether the target object targeted by the target operation is a monitoring object according to the storage path of the target object targeted by the target operation; if so, execute step S205; if not, execute step S211.
[0087] S205. Determine whether the target object has not been backed up according to the metadata of the target object; if so, execute step S206; if not, execute step S211.
[0088] S206: Back up the target object targeted by the target operation to obtain a backup object, and record an operation log of the target operation.
[0089] S207: Execute the target operation on the target object.
[0090] S208: Is there a new target operation? If so, execute step S202; if not, execute step S209.
[0091] S209. In response to a preset instruction or in response to an execution error in the target operation, the target object is restored using the backup objects corresponding to the log entries in reverse order of the recording time of each log entry in the operation log until the target object is restored to the backup object corresponding to the preset log entry.
[0092] S210. Delete the restored backup object and the operation log corresponding to the backup object, and execute step S212.
[0093] S211. Refuse to back up the target object.
[0094] S212: In response to the instruction to exit monitoring, the backup object and the operation log are deleted.
[0095] In a second aspect, an embodiment of the present invention further provides a backup device that can effectively reduce the initialization runtime overhead and storage space overhead of the backup operation.
[0096] like Figure 4 As shown, the backup device provided by the embodiment of the present invention may include: A monitoring unit 31, configured to monitor a target operation based on a virtual file system of an operating system kernel, and suspend the target operation before the target operation is executed; A backup unit 32, configured to back up the target object targeted by the target operation to obtain a backup object, wherein the target object includes a target file and / or a target directory; The execution unit 33 is configured to execute the target operation on the target object.
[0097] The backup device provided by the embodiment of the present invention can monitor the target operation based on the virtual file system of the operating system kernel, suspend the target operation before the target operation is executed, back up the target object targeted by the target operation, and obtain the backup object, wherein the target object includes the target file and / or the target directory, and the target operation is executed on the target object. In this way, it is only necessary to monitor the target operation and back up the target object before the target object is processed by the target operation. If the target operation is not monitored, there is no need to perform the corresponding backup, instead of backing up all the monitored files and directories as in the related art. Therefore, the initialization running time overhead and storage space overhead of the backup operation can be effectively reduced.
[0098] In one embodiment, the monitoring unit 31 is specifically used to monitor the target operation and suspend the target operation before the target operation is executed based on a hook function pre-set at the application interface of the target operation in the virtual file system; the backup unit 32 is specifically used to back up the target object targeted by the target operation in the hook function to obtain the backup object.
[0099] In one embodiment, the monitoring unit 31 is specifically used to obtain the operation association information of the target operation through the hook function and suspend the target operation when the target operation is called based on the application interface, wherein the operation association information includes: the identifier of the initiator of the target operation, the storage path of the target object targeted by the target operation, and the metadata of the target object; the backup unit 32 is specifically used to back up the target object based on the operation association information in the hook function to obtain the backup object.
[0100] In one implementation, the backup unit 32 may include: A first determination module is used to determine whether the initiator of the target operation is an associated process of a preset application according to the identifier of the initiator of the target operation, wherein the associated process of the preset application includes the process of the preset application and / or a subprocess of the process; a second determination module, configured to determine, in response to the initiator of the target operation being an associated process of the preset application, whether the target object targeted by the target operation is a monitoring object according to a storage path of the target object targeted by the target operation; The backup module is used for backing up the target object in response to the target object being the monitored object to obtain the backup object.
[0101] In one implementation, the backup module is specifically configured to: determine whether the target object has not been backed up based on the metadata of the target object; and in response to the target object not being backed up, back up the target object to obtain the backup object.
[0102] In one embodiment, the backup unit 32 also includes: a first rejection module, which is used to determine whether the initiator of the target operation is an associated process of a preset application based on the identifier of the initiator of the target operation, and then refuse to back up the target object in response to the initiator of the target operation not being an associated process of the preset application.
[0103] In one embodiment, the backup unit 32 also includes: a second rejection module, which is used to determine whether the target object targeted by the target operation is a monitored object based on the storage path of the target object targeted by the target operation, and in response to the target object not being the monitored object, refuse to back up the target object.
[0104] In one implementation, the number of initiators of the target operation is at least one.
[0105] In one implementation, the metadata includes at least one of the following: object type, object operation permission, object owner, object size, object access information, and data block location of a file-type object.
[0106] In one embodiment, the backup device also includes a setting unit for setting the hook function at the application interface of the target operation in the virtual file system based on a hook function pre-set at the application interface of the target operation in the virtual file system, monitoring the target operation and suspending the target operation before the target operation is executed, and setting the hook function at the application interface of the target operation in the virtual file system through the virtual machine running in the operating system kernel.
[0107] In one implementation, the backup unit is specifically configured to back up the target object targeted by the target operation, obtain the backup object, and record an operation log of the target operation.
[0108] In one implementation, the operation log includes: the operation type of the target operation, the target object targeted by the target operation, and the storage path of the backup object of the target object.
[0109] In one implementation, the operation type of the target operation includes at least one of the following: creating a new object, modifying object content, deleting an object, renaming an object, and creating an object link.
[0110] In one embodiment, the device also includes a recovery unit for restoring the target object to the backup object based on the operation log and the backup object of the target object in response to a preset instruction or in response to an execution error of the target operation after performing the target operation on the target object.
[0111] In one embodiment, the operation log includes at least one log entry, wherein each log entry has a corresponding backup object; the recovery unit is specifically used to perform recovery operations on the target object in reverse order of the recording time of each log entry in the operation log, using the backup objects corresponding to each log entry in sequence, until the target object is restored to the backup object corresponding to the preset log entry.
[0112] In one implementation, the preset log entry includes a log entry recorded for the first time in the operation log corresponding to the target object.
[0113] In one embodiment, the device further includes a first deleting unit for deleting the restored backup object and the operation log corresponding to the backup object after restoring the target object to the backup object based on the operation log and the backup object of the target object.
[0114] In one embodiment, the device also includes a second deletion unit, which is used to delete the backup object and the operation log in response to an instruction to exit monitoring after backing up the target object targeted by the target operation, obtaining the backup object, and recording the operation log of the target operation.
[0115] In a third aspect, an embodiment of the present invention further provides an electronic device that can effectively reduce the initialization runtime overhead and storage space overhead of a backup operation.
[0116] like Figure 5 As shown, the electronic device provided by an embodiment of the present invention may include: a housing 51, a processor 52, a memory 53, a circuit board 54 and a power supply circuit 55, wherein the circuit board 54 is arranged inside the space enclosed by the housing 51, and the processor 52 and the memory 53 are arranged on the circuit board 54; the power supply circuit 55 is used to supply power to various circuits or devices of the above-mentioned electronic device; the memory 53 is used to store executable program codes; the processor 52 runs a program corresponding to the executable program code by reading the executable program code stored in the memory 53, so as to execute the backup method provided by any of the aforementioned embodiments.
[0117] The specific execution process of the above steps by the processor 52 and the steps further executed by the processor 52 by running the executable program code can be found in the description of the previous embodiment, which will not be repeated here.
[0118] In the fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, which stores one or more programs, and the one or more programs can be executed by one or more processors to implement any one of the backup methods provided in the aforementioned embodiments, thereby also achieving the corresponding technical effects, which have been described in detail above and will not be repeated here.
[0119] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including 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, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0120] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referenced to each other, and each embodiment focuses on the differences from other embodiments.
[0121] In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0122] For the convenience of description, the above device is described by dividing the functions into various units / modules. Of course, when implementing the present invention, the functions of each unit / module can be implemented in the same or multiple software and / or hardware.
[0123] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0124] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.
Claims
1. A backup method, characterized in that: include: A virtual file system based on an operating system kernel monitors a target operation and suspends the target operation before the target operation is executed; Backing up the target object targeted by the target operation to obtain a backup object, wherein the target object includes a target file and / or a target directory; The target operation is performed on the target object.
2. The method according to claim 1, characterized in that The virtual file system based on the operating system kernel monitors the target operation and suspends the target operation before the target operation is executed, including: Based on a hook function pre-set at the application program interface of the target operation in the virtual file system, monitoring the target operation and suspending the target operation before the target operation is executed; The backing up of the target object targeted by the target operation to obtain the backup object comprises: In the hook function, the target object targeted by the target operation is backed up to obtain the backup object.
3. The method according to claim 2, characterized in that The hook function pre-set at the application program interface of the target operation in the virtual file system, monitoring the target operation and suspending the target operation before the target operation is executed includes: When the target operation is called based on the application program interface, the operation association information of the target operation is obtained through the hook function and the target operation is suspended, wherein the operation association information includes: the identifier of the initiator of the target operation, the storage path of the target object targeted by the target operation, and the metadata of the target object; In the hook function, backing up the target object targeted by the target operation, and obtaining the backup object includes: In the hook function, the target object is backed up based on the operation association information to obtain the backup object.
4. The method according to claim 3, characterized in that In the hook function, the target object is backed up based on the operation association information to obtain the backup object, including: Determining, according to the identifier of the initiator of the target operation, whether the initiator of the target operation is an associated process of a preset application, wherein the associated process of the preset application includes the process of the preset application and / or a subprocess of the process; In response to the initiator of the target operation being an associated process of the preset application, determining whether the target object targeted by the target operation is a monitoring object according to a storage path of the target object targeted by the target operation; In response to the target object being the monitored object, backing up the target object to obtain the backup object.
5. The method according to claim 4, characterized in that In response to the target object being the monitored object, backing up the target object to obtain the backup object includes: Determining, according to the metadata of the target object, whether the target object has not been backed up; In response to the target object not having been backed up, backing up the target object to obtain the backup object.
6. The method according to claim 4, characterized in that After determining, according to the identifier of the initiator of the target operation, whether the initiator of the target operation is an associated process of a preset application, the method further includes: In response to the initiator of the target operation not being an associated process of the preset application, backing up the target object is rejected.
7. The method according to claim 4, characterized in that After determining whether the target object targeted by the target operation is a monitoring object according to the storage path of the target object targeted by the target operation, the method further includes: In response to the target object not being the monitored object, backing up the target object is rejected.
8. The method according to claim 3, characterized in that The number of initiators of the target operation is at least one.
9. The method according to claim 3, characterized in that: The metadata includes at least one of the following: object type, object operation permission, object owner, object size, object access information, and data block location of file-type objects.
10. The method according to claim 2, characterized in that Before monitoring the target operation and suspending the target operation before the target operation is executed based on the hook function pre-set at the application program interface of the target operation in the virtual file system, the method further includes: The hook function is set at the application program interface of the target operation in the virtual file system through the virtual machine running in the operating system kernel.