A directory non-recovery method based on a Linux system
By creating large files in the Linux system's hard disk protection partition and building a directory mapping relationship, the problem of specified data loss during system restoration is solved, and data retention and rapid system recovery are achieved.
Patent Information
- Application Number
- CN202111273458.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-29
- Publication Date
- 2025-10-17
- Estimated Expiration
- 2041-10-29
AI Technical Summary
In the common environment of Linux systems, the specified data cannot be retained during system restoration, resulting in system damage and data loss caused by unexpected operations.
Create a large file in the hard disk's protected partition and virtualize it into a file system device. Build a mapping between the source directory and the target directory, and automatically load it at startup through system commands or driver programs to ensure that the specified directory is not overwritten during the restore process.
This ensures that data in the specified directory is not overwritten when the Linux system is restored, maintaining the integrity of the system and retaining user data, simplifying the maintenance process, and saving system recovery time.
Smart Images

Figure CN113918387B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of system restoration, and more particularly to a directory non-restoration method based on a Linux system. BACKGROUND
[0002] Under the situation that operating systems pursue independence, the Linux operating system developed independently by China is becoming more and more popular. For computers used in public environments, such as computer classrooms in schools, computer equipment in libraries and the like, since they are provided for use by different personnel, accidental operations are prone to occur, resulting in problems such as damage to the operating system, computer poisoning, installation of malicious software and the like. Therefore, based on the convenience of maintaining computers in public environments, a protection software for real-time restoration of the Linux operating system is developed. Regardless of any situation of the operating system, the computer system can be restored to the state before being damaged instantaneously by only rebooting, thereby avoiding the need to reinstall the operating system and deploy application software, saving a large amount of time spent on troubleshooting of the computer operating system and facilitating maintenance personnel to easily complete the maintenance work of the computer.
[0003] For the Linux operating system installed with the system restoration software, when the maintenance personnel performs a system restoration operation, all data in the protected hard disk space will be restored to the set state in real time. However, in some cases, some data needs to be retained on the computer, and people hope that the part of data can not be restored when the user performs the restoration operation. SUMMARY
[0004] In view of the deficiencies in the prior art, the purpose of the present application is to provide a directory non-restoration method based on a Linux system, which can prevent some specified data from being restored when the Linux system performs a system restoration operation.
[0005] To achieve the above purpose, the present application provides the following technical solution: a directory non-restoration method based on a Linux system, comprising
[0006] S1. Creating a large file of a specified size in a protection partition of a hard disk, locking the position of the large file in the hard disk in a file system, and determining a sector distribution list of the large file in the hard disk;
[0007] S2. Virtually forming a sector distribution list corresponding to the large file into a file system device, marking the file system device as an A partition, and removing the large file from the corresponding sector distribution list from the protection partition;
[0008] S3, marking the directory needing to be set as non-redundant as a source directory, copying the source directory in the A partition to obtain a target directory, writing the correspondence between the source directory and the target directory into the large file and completing mapping;
[0009] S4, setting the correspondence between the source directory and the target directory to be automatically loaded at startup by a system command mode or by a driver mode and completing mapping.
[0010] As a further improvement of the present application, the S2 comprises:
[0011] S21, calling losetup to create a large file into a memory loop device;
[0012] S22, calling fdisk to create a primary partition for the memory loop device;
[0013] S23, calling mkfs.ext4 to format the primary partition into a standard ext4 partition;
[0014] S24, loading the ext4 partition into a file system.
[0015] As a further improvement of the present application, the S22 further comprises reserving a preset capacity size of a save space when creating the primary partition, and the save space is used for saving various parameters during function running.
[0016] As a further improvement of the present application, in the S3, the correspondence between the source directory and the target directory is written into the save space;
[0017] The parameters saved into the save space comprise a parameter structure header and a parameter structure data part, the parameter structure header comprises the number of directory non-redundant setting items and the offset of detailed setting data in the whole structure, and the parameter structure data part comprises specific detail parameters corresponding to the setting of the directory non-redundant setting item, the original directory path corresponding to the setting of the directory non-redundant setting item, and the target data path corresponding to the setting of the directory non-redundant setting item.
[0018] As a further improvement of the present application, the S3 further comprises:
[0019] S31, calling cp-rf to complete consistency before and after data mapping between the source directory and the target directory;
[0020] S32, calling mount-bind to build a temporary mapping relationship between the source directory and the target directory.
[0021] As a further improvement of the present application, the S4 sets the corresponding relationship of the source directory and the target directory to be automatically loaded at startup by a system command mode and completes mapping, specifically:
[0022] As a further improvement of the present application, the S4 sets the corresponding relationship of the source directory and the target directory to be automatically loaded at startup by a driver mode and completes mapping, specifically:
[0023] S41, the ftrace_set_filter_ip is called to start the ftrace filtering function, and the filtering callback function fh_ftrace_thunk is set;
[0024] S42, the register_ftrace_function is called to register the process callback of the system method vfs_open, the custom filtering function is new_vfs_open, and the original function is real_vfs_open; the custom filtering function obtains the file path in the request, compares whether the path is in the set non-recovery directory list or whether it is a sub-path of a certain path in the non-recovery directory list, if yes, step S43 is entered, if not, the real_vfs_open is called to read the original file;
[0025] S43, the target path is found according to the non-recovery directory original path, the original path part in the request path is replaced, and the final mapped target path is obtained;
[0026] S44, the real_vfs_open is called to open the mapped target path.
[0027] The present application has the advantages that: by creating a large file in the protection partition of the hard disk and excluding the sector distribution list corresponding to the large file, the non-recovery of the large file is realized, by constructing the mapping of the source directory and the target directory, the read-write-modification operations of the files under the source directory are mapped to the operations on the same name files in the corresponding target directory in the large file, and the automatic mapping after the computer startup is realized by the system command mode or the driver mode. Since the data in the large file will not be recovered, the operations on the same name files corresponding to the source directory will not be recovered, so that the method can make the data in the specified source directory not be recovered in the eyes of the computer user when the Linux system performs the system recovery operation. BRIEF DESCRIPTION OF DRAWINGS
[0028] Figure 1 A schematic diagram of the relationship between the large file and the protection partition of the hard disk;
[0029] Figure 2Structure diagram for saving parameters to a saving space;
[0030] Figure 3 Flow chart for mapping relationship component;
[0031] Figure 4 Flow chart for automatically building mapping relationship by system command mode at startup;
[0032] Figure 5 Flow chart for automatically building mapping relationship by driver program mode at startup;
[0033] Figure 6 Flow chart for filtering after startup by driver program mode. DETAILED DESCRIPTION
[0034] The application will be further described in detail below with reference to the accompanying drawings and embodiments.
[0035] Embodiment 1
[0036] Referring to Figure 1 , Figure 3 , the directory non-recovery method based on Linux system in the embodiment includes S1, creating a large file of specified size in a protection partition of a hard disk, locking the large file in the hard disk in a file system, and determining a sector distribution list of the large file in the hard disk.
[0037] S2, virtually forming a file system device corresponding to the sector distribution list of the large file, marking the file system device as A partition, and removing the large file from the corresponding sector distribution list in the protection partition.
[0038] Specifically, the principle of the recovery system is that the recovery system is based on sector level, that is, for the recovery system, file operation, partition operation, etc. are all read and write of sectors. The hard disk interval protected by the recovery system means that the modification on the sectors in the interval will not be actually written to the corresponding sectors on the hard disk. The modification on the sectors in the unprotected hard disk interval will be actually written to the corresponding sectors. In the actual application process, the protection interval of the hard disk is divided in units of partitions, that is, the protected partition and the unprotected partition are set. In the S1 step, a large file needs to be newly created in the protected partition, and the large file occupies a certain position in the protected partition, which can also be called an occupying file. The sector distribution list of the large file is calculated, and the sector list is removed from the sector interval protected by the recovery system. And the large file needs to be locked in the file system to prevent being moved.
[0039] Referring to Figure 3 , step S2 includes:
[0040] S21, calling losetup -p loop1204 to create a large file into a memory loop device, and the name of the created loop device is / dve / loop1204.
[0041] S22, calling fdisk / dev / loop1204 to create a primary partition with automatic size for the memory loop device, and the device ID of the primary partition is / dev / loop1204p1. When creating the primary partition, a preset capacity of the saving space is reserved, and the saving space is used to save various parameters during the running of the function. In this embodiment, the size of the saving space is set to 10M.
[0042] S23, calling mkfs.ext4 / dev / loop1204p1 to format the primary partition into a standard ext4 partition.
[0043] S24, calling mount / dev / loop1204p1 / mnt to load the partition into the file system.
[0044] S3, marking the directory which needs to be set as not to be restored as a source directory, copying the source directory in the A partition to obtain a target directory, and writing the corresponding relationship between the source directory and the target directory into the saving space in the large file and completing the mapping.
[0045] Specifically, the mapping relationship is constructed and saved as follows: 1. The 10M saving space at the beginning of the large file is used to save various parameters during the running of the function, and because the saving space is removed from the protection partition together with the large file, the data in the 10M saving space will not be restored. 2. The parameters saved into the saving space include a parameter structure header and a parameter structure data part. As shown in FIG. 4, the parameter structure header has two parameters related to the directory non-restore function, which are updCount and updltemsOffset, wherein updCount indicates how many directory non-restore setting items, and updltemsOffset is the offset of the detailed setting data in the entire structure, and the detailed setting data is saved in the parameter structure data part. The parameter structure data part includes param, src and obj, wherein param indicates the specific detail parameters of the setting, such as whether to take effect or not; src indicates the original directory path of the setting; and obj indicates the target data path of the setting. Figure 2
[0046] The construction process is as follows: referring to FIG. 4, the parameter structure header is first constructed, and then the parameter structure data part is constructed. Figure 3 As shown, 1, set the directory / data / souce as not to be restored, and the process of constructing the virtual disk in step S2 above is completed. 2, call cp -rf / data / souce / mnt / data / souce to complete the consistency before and after the data mapping. 3, call mount -bind / mnt / data / souce / data / souce to construct a temporary mapping relationship.
[0047] Referring to Figure 4 As shown, S4, set the corresponding relationship of the source directory and the target directory to be automatically loaded at startup by the system command mode and complete the mapping. Specifically, modify fstab to automatically construct the mapping relationship during the startup process, add the bind operation of / mnt / data / souce to / data / souce.
[0048] Embodiment 2:
[0049] Referring to Figure 5 , Figure 6 As shown, the difference between this embodiment and embodiment 1 is that S4, set the corresponding relationship of the source directory and the target directory to be automatically loaded at startup by the driver mode and complete the mapping. Specifically:
[0050] S41, call ftrace_set_filter_ip to start the ftrace filtering function and set the filtering callback function fh_ftrace_thunk.
[0051] S42, call register_ftrace_function to register the process callback of the system method vfs_open, set the custom filtering function as new_vfs_open, and set the original function as real_vfs_open. All file opening operations in the system will call new_vfs_open, which handles the mapping relationship in new_vfs_open. The logic of new_vfs_open is: obtain the file path in the request, compare whether the path is in the set non-restoration directory list, or whether it is a sub-path of a certain path in the non-restoration directory list, if yes, go to step S43, if not, call real_vfs_open to read the original file.
[0052] S43, find the target path according to the original path of the non-restoration directory, replace the original path part in the request path, and obtain the final mapping target path.
[0053] S44, call real_vfs_open to open the mapped target path.
[0054] The above are only preferred embodiments of the present application, and the protection scope of the present application is not limited to the above-mentioned embodiments. Any technical scheme falling within the concept of the present application shall fall within the protection scope of the present application. It should be noted that, for ordinary skilled persons in the art, some improvements and refinements without departing from the principles of the present application shall also be considered as falling within the protection scope of the present application.
Claims
1. A method for not restoring a directory based on a Linux system, characterized by: include S1, creating a large file of a specified size in a protected partition of a hard disk, locking the location of the large file on the hard disk in a file system, and determining a sector distribution list of the large file on the hard disk; S2, virtualizing the sector distribution list corresponding to the large file into a file system device, marking the file system device as partition A, and removing the large file from the corresponding sector distribution list in the protection partition; S3, marking the directory that needs to be set not to be restored as the source directory, copying the source directory in the A partition to obtain the target directory, writing the correspondence between the source directory and the target directory into the large file to complete the mapping; S4, setting the corresponding relationship between the source directory and the target directory to be automatically loaded upon startup through a system command or a driver program and completing the mapping; The S2 includes: S21, call losetup to create a memory loop device for the large file; S22, calling fdisk to create a primary partition for the memory loop device; when creating the primary partition, a storage space of a preset capacity is reserved, and the storage space is used to store various parameters during function operation; S23, call mkfs.ext4 to format the primary partition as a standard ext4 partition; S24, loading the ext4 partition into the file system.
2. The method for not restoring a directory based on a Linux system according to claim 1, characterized in that: In S3, the correspondence between the source directory and the target directory is written into the storage space; The parameters saved to the storage space include a parameter structure header and a parameter structure data part. The parameter structure header includes the number of directory non-restore setting items and the offset of the detailed setting data in the entire structure. The parameter structure data part includes the specific detail parameters corresponding to the directory non-restore setting item, the original directory path corresponding to the directory non-restore setting item, and the target data path corresponding to the directory non-restore setting item.
3. The method for not restoring a directory based on a Linux system according to claim 1, characterized in that: Said S3 further comprises: S31, calling cp-rf to complete the consistency of data mapping between the source directory and the target directory; S32, call mount-bind to build a temporary mapping relationship between the source directory and the target directory.
4. The method for not restoring a directory based on a Linux system according to claim 1, characterized in that: In the S4, the corresponding relationship between the source directory and the target directory is set to be automatically loaded at startup and the mapping is completed through a system command, specifically: modifying fstab to automatically build a mapping relationship during the startup process, and adding a bind operation of the target directory to the source directory.
5. The method for not restoring a directory based on a Linux system according to claim 1, characterized in that: In S4, the corresponding relationship between the source directory and the target directory is set to be automatically loaded at startup and the mapping is completed by the driver, specifically: S41, call ftrace_set_filter_ip to enable the ftrace filtering function and set the filtering callback function fh_ftrace_thunk; S42, call register_ftrace_function to register the process callback of the system method vfs_open, the custom filter function is new_vfs_open, and the original function is real_vfs_open; the custom filter function obtains the file path in the request and compares whether the path is in the set non-restore directory list, or whether it is a subpath of a directory in the non-restore directory list. If so, the process proceeds to step S43, otherwise call real_vfs_open to read the original file; S43, finding the target path according to the original path of the unrestored directory, replacing the original path part in the request path, and obtaining the final mapped target path; S44, calls real_vfs_open to open the mapped target path.
Citation Information
Patent Citations
Method for not restoring write-ins in overall restoring condition of computer system
CN102799798A
System and method for realizing user partition recovery for shared intelligent equipment
CN107656837A