Backup and restoration method and device of operating system, electronic equipment and storage medium

CN117520049BActive Publication Date: 2026-08-21CHINA UNITED NETWORK COMM GRP CO LTD +2
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202311433216.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-10-31
Publication Date
2026-08-21
Estimated Expiration
2043-10-31

AI Technical Summary

Technical Problem

[0002]现有的备份方式需要使用额外的存储设备,用于存放备份还原系统和备份文件,在还原时需要连接存储设备,当待备份文件或待备份系统占用存储空间较大时,备份还原需要花费时间较多,且备份和还原过程需要一定的技术基础,较为不便

Benefits of technology

[0016] The technical solution provided in this application provides at least the following beneficial effects: The backup and restore device creates a sub-volume corresponding to the file to be backed up in the operating system of the target device; the target device includes a first storage space and a second storage space, and the operating system is located in the first storage space. This application creates a sub-volume corresponding to the file to be backed up in the operating system of the target device, solving the problem that special files cannot be made into sub-volumes and cannot be quickly backed up in conjunction with snapshot operations, enabling the backup and restore device to perform separate backup and restore of special files. In response to a backup command for the operating system, the backup and restore device generates a first mount point and mounts the target device to the first mount point; performs a backup operation on the sub-volume to be backed up in the first mount point to obtain a snapshot corresponding to the sub-volume to be backed up; creates a preset file in the second storage space and stores the snapshot in the preset file; unmounts the target device and deletes the first mount point to complete the backup operation. Compared to existing technologies where skilled personnel use additional storage devices to perform backup and restore operations, this application uses a simple and easy-to-use script to create subvolumes corresponding to the files to be backed up via the btrfs file system. Then, it combines the snapshot function to achieve backup of files or important data. This does not require connecting to a storage device, the process is simpler, and the combination of snapshot function reduces the time spent on backup, thus improving backup efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117520049B_ABST
    Figure CN117520049B_ABST
Patent Text Reader

Abstract

The application provides a backup and restoration method and device of an operating system, electronic equipment and a storage medium, relates to the technical field of computers, and is used for completing the creation and mounting operation of a subvolume corresponding to a file to be backed up, thereby realizing the backup operation of the file to be backed up and the restoration operation of a file to be restored. The method comprises the following steps: creating a to-be-backed-up subvolume corresponding to a file to be backed up in an operating system of a target device; in response to a backup instruction of the operating system, generating a first mounting point and mounting the target device on the first mounting point; performing a backup operation on the to-be-backed-up subvolume in the first mounting point to obtain a snapshot corresponding to the to-be-backed-up subvolume; creating a preset file in a second storage space and storing the snapshot in the preset file; uninstalling the target device and deleting the first mounting point to complete the backup operation; and in response to a restoration instruction of the operating system, restoring the content in a to-be-restored snapshot to the operating system to complete the restoration operation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a method, apparatus, electronic device, and storage medium for backing up and restoring an operating system. Background Technology

[0002] Existing backup methods require additional storage devices to store backup and restore systems and backup files. The storage device needs to be connected during restoration. When the files or systems to be backed up occupy a large amount of storage space, the backup and restore process takes a long time. Furthermore, the backup and restore process requires a certain level of technical expertise, which is quite inconvenient.

[0003] Creating subvolumes based on the btrfs file system, combined with snapshot functionality, can quickly achieve backup and restore functions without requiring external storage devices. However, it often backs up the entire system / directory, and cannot create subvolumes to back up special files that cannot be changed to the btrfs file type. Summary of the Invention

[0004] This application provides a method, apparatus, electronic device, and storage medium for backing up and restoring an operating system, used to create and mount subvolumes corresponding to files to be backed up, thereby enabling backup operations on files to be backed up and restoration operations on files to be restored.

[0005] To achieve the above objectives, this application adopts the following technical solution:

[0006] In a first aspect, a method for backing up and restoring an operating system is provided. The method includes: creating a sub-volume to be backed up corresponding to a file to be backed up in the operating system of a target device; the target device includes a first storage space and a second storage space, and the operating system is located in the first storage space; in response to a backup command for the operating system, generating a first mount point and mounting the target device to the first mount point; performing a backup operation on the sub-volume to be backed up in the first mount point to obtain a snapshot corresponding to the sub-volume to be backed up; creating a preset file in the second storage space and storing the snapshot in the preset file; unmounting the target device and deleting the first mount point to complete the backup operation.

[0007] Optionally, the method further includes: in response to a mount command on the operating system, mounting the subvolume to be backed up to a second mount point, and using the second mount point as the restore path.

[0008] Optionally, the method further includes: in response to the restore command of the operating system, generating a third mount point and mounting the target device to the third mount point; taking the snapshot corresponding to the subvolume to be backed up as the snapshot to be restored, performing the restore operation on the snapshot to be restored in the third mount point, sending the snapshot to be restored to the second mount point, and deleting the subvolume to be backed up in the second mount point; unmounting the target device and deleting the third mount point to complete the restore operation.

[0009] Optionally, a subvolume corresponding to the file to be backed up can be created in the operating system of the target device, including: if the file type of the file to be backed up can be changed to btrfs file type, then the changed file to be backed up is identified as the subvolume to be backed up; if the file type of the file to be backed up cannot be changed to btrfs file type, then an empty subvolume is created in the default mount directory of the operating system, and the contents of the file to be backed up are copied into the empty subvolume to obtain the subvolume corresponding to the file to be backed up.

[0010] Secondly, a backup and restore device for an operating system is provided. The backup and restore device includes a creation unit, a processing unit, a backup unit, and an unloading unit. The creation unit is used to create a sub-volume to be backed up corresponding to the file to be backed up in the operating system of the target device. The target device includes a first storage space and a second storage space, and the operating system is located in the first storage space. The processing unit is further used to generate a first mount point in response to a backup command for the operating system and mount the target device to the first mount point. The backup unit is further used to perform a backup operation on the sub-volume to be backed up in the first mount point to obtain a snapshot corresponding to the sub-volume to be backed up. The creation unit is further used to create a preset file in the second storage space and store the snapshot in the preset file. The unloading unit is further used to unload the target device and delete the first mount point to complete the backup operation.

[0011] Optionally, the processing unit is specifically used to: in response to a mount command from the operating system, mount the subvolume to be backed up to a second mount point, and use the second mount point as the restore path.

[0012] Optionally, the processing unit is specifically configured to: in response to the restore command of the operating system, generate a third mount point and mount the target device to the third mount point; take the snapshot corresponding to the subvolume to be backed up as the snapshot to be restored, perform the restore operation on the snapshot to be restored in the third mount point, send the snapshot to be restored to the second mount point, and delete the subvolume to be backed up in the second mount point; unmount the target device and delete the third mount point to complete the restore operation.

[0013] Optionally, the processing unit is specifically used for: if the file type of the file to be backed up can be changed to the btrfs file type, then the changed file to be backed up is identified as the subvolume to be backed up; if the file type of the file to be backed up cannot be changed to the btrfs file type, then an empty subvolume is created in the operating system's default mount directory, and the contents of the file to be backed up are copied into the empty subvolume to obtain the subvolume to be backed up corresponding to the file to be backed up.

[0014] Thirdly, an electronic device is provided, comprising: a processor and a memory for storing processor-executable instructions; wherein the processor is configured to execute instructions to implement the operating system backup and restore method of the first aspect described above.

[0015] Fourthly, a computer-readable storage medium is provided, on which instructions are stored, such that when the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is able to execute the backup and restore method of the operating system as described in the first aspect above.

[0016] The technical solution provided in this application provides at least the following beneficial effects: The backup and restore device creates a sub-volume corresponding to the file to be backed up in the operating system of the target device; the target device includes a first storage space and a second storage space, and the operating system is located in the first storage space. This application creates a sub-volume corresponding to the file to be backed up in the operating system of the target device, solving the problem that special files cannot be made into sub-volumes and cannot be quickly backed up in conjunction with snapshot operations, enabling the backup and restore device to perform separate backup and restore of special files. In response to a backup command for the operating system, the backup and restore device generates a first mount point and mounts the target device to the first mount point; performs a backup operation on the sub-volume to be backed up in the first mount point to obtain a snapshot corresponding to the sub-volume to be backed up; creates a preset file in the second storage space and stores the snapshot in the preset file; unmounts the target device and deletes the first mount point to complete the backup operation. Compared to existing technologies where skilled personnel use additional storage devices to perform backup and restore operations, this application uses a simple and easy-to-use script to create subvolumes corresponding to the files to be backed up via the btrfs file system. Then, it combines the snapshot function to achieve backup of files or important data. This does not require connecting to a storage device, the process is simpler, and the combination of snapshot function reduces the time spent on backup, thus improving backup efficiency. Attached Figure Description

[0017] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0018] Figure 1 This application provides a schematic diagram of a backup and restore system structure.

[0019] Figure 2 A flowchart illustrating an operating system backup and restore method provided in this application embodiment. Figure 1 ;

[0020] Figure 3 A schematic diagram of a backup and restore device provided in this application embodiment. Figure 1 ;

[0021] Figure 4 A flowchart illustrating an operating system backup and restore method provided in this application embodiment. Figure 2 ;

[0022] Figure 5 A flowchart illustrating an operating system backup and restore method provided in this application embodiment. Figure 3 ;

[0023] Figure 6 A schematic diagram of the structure of a backup and restore device provided in this application embodiment. Figure 2 ;

[0024] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0025] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0026] It should be noted that in the embodiments of this application, the words "exemplary" or "for example" are used to indicate examples, illustrations, or explanations. Any embodiment or design scheme described as "exemplary" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design schemes. Specifically, the use of the words "exemplary" or "for example" is intended to present the relevant concepts in a specific manner.

[0027] It should also be noted that in the embodiments of this application, "of", "corresponding", and "corresponding" can sometimes be used interchangeably. It should be pointed out that when their differences are not emphasized, their meanings are consistent.

[0028] To facilitate a clear description of the technical solutions of the embodiments of this application, the terms "first" and "second" are used in the embodiments of this application to distinguish the same or similar items with essentially the same function and effect. Those skilled in the art can understand that the terms "first" and "second" are not intended to limit the quantity or execution order.

[0029] Before providing a detailed explanation of the embodiments of this application, some relevant technical terms and technologies involved in the embodiments of this application will be introduced first.

[0030] In real-time business operations running on the Linux operating system, stable data collection and transmission are required. When an anomaly occurs in the real-time business system, data or files may be lost, and it is necessary to combine the restore function to restore backup files or important backup data.

[0031] The local backup and restore functions provided by the Linux operating system are not yet fully developed for backing up and restoring critical data. For example, the built-in copy (cp) and tape archive (tar) commands are inadequate. The cp command is primarily used to copy one or more files or directories to a specified location, commonly used for file backups; tar is an archive file format typically used to package multiple files into a single file. When backing up or restoring large files or data, the backup or restore process is relatively slow, and system interruptions can lead to backup or restore failures.

[0032] Existing backup methods generally include system-level backup and file-level backup. System-level backup involves periodically performing a full system backup and directly rolling back the system in case of failure. File-level backup typically involves periodically backing up files and restoring the backup files in case of failure or file loss.

[0033] However, existing system-level and file-level backup methods require additional storage devices to store the backup and restore system and backup files. These storage devices need to be connected during restoration. When the files or systems to be backed up occupy a large amount of storage space, the backup and restore process takes a long time. Furthermore, the backup and restore process requires staff to have a certain level of technical expertise, which is quite inconvenient.

[0034] Btrfs (also known as Butter FS) is a copy-on-write (COW) file system. By creating subvolumes corresponding to the files to be backed up using Btrfs and combining this with snapshot functionality, a backup of the files can be obtained. This allows for relatively fast backup and restore without requiring external storage devices. However, it often backs up the entire system / directory, and cannot create subvolumes for certain special files. For example, regular files like / var (used to store files whose data needs to be changed at runtime, i.e., the overflow area of ​​some large files, such as log files of various services, system startup logs, etc.) and / log (usually records of certain processes completed by the system or some software for future reference) can be directly converted to Btrfs file types. By changing their file type, their corresponding subvolumes can be directly obtained, and then combined with snapshot functionality, backup and restore can be achieved quickly. However, special files like / etc (used to store system management and configuration files) cannot be created by directly changing their file type to Btrfs.

[0035] In view of the above problems, this application provides a backup and restore method for an operating system. The backup and restore device creates a sub-volume to be backed up corresponding to the file to be backed up in the operating system of the target device. The target device includes a first storage space and a second storage space, and the operating system is located in the first storage space. Responding to a user's backup command for the operating system, the backup and restore device generates a first mount point and mounts the target device to the first mount point; performs a backup operation on the sub-volume to be backed up in the first mount point to obtain a snapshot corresponding to the sub-volume; creates a preset file in the second storage space and stores the snapshot in the preset file; unmounts the device and deletes the first mount point to complete the backup operation. Responding to a user's restore command for the operating system, the backup and restore device completes the restore operation.

[0036] The backup and restore method of the operating system provided in the embodiments of this application will be described in detail below with reference to the accompanying drawings.

[0037] The operating system backup and restore method provided in this application embodiment can be applied to backup and restore systems. Figure 1 A schematic diagram of the backup and restore system is shown. For example... Figure 1 As shown, the backup and restore system 10 includes a backup and restore device 11 and a server 12. The backup and restore device 11 and the server 12 can be connected by a wired connection or a wireless connection, and this embodiment does not limit the connection.

[0038] Server 12 can pass mandatory parameters, optional parameters, mount commands, backup commands, and restore commands to backup and restore device 11 to instruct backup and restore device 11 to perform backup and restore operations.

[0039] The backup and restore device 11 can receive mandatory parameters and optional parameters transmitted by the server 12 to complete the mounting operation with the mounting command, the backup operation with the backup command, and the restore operation with the restore command. The specific backup and restore methods of the operating system can be referred to the description in the following embodiments, which will not be repeated here.

[0040] The backup and restore device 11 can be an electronic device with data processing capabilities, such as a computer, tablet computer, laptop computer, ultra-mobile personal computer (UMPC), etc. The specific type of backup and restore device 11 is not limited in this application embodiment.

[0041] Server 12 can be a single server, a server cluster, or a chip or system-on-a-chip within a server. This application embodiment does not limit the specific type of server.

[0042] Figure 2 This is a flowchart illustrating an operating system backup and restore method according to some exemplary embodiments. In some embodiments, the above-described operating system backup and restore method can be applied to, for example... Figure 1 The backup and restore device shown can also be applied to other similar devices.

[0043] like Figure 2 As shown, the operating system backup and restore method provided in this application embodiment includes the following S201-S206.

[0044] S201. Create a subvolume corresponding to the file to be backed up in the operating system of the target device.

[0045] The target device includes a first storage space and a second storage space, with the operating system located in the first storage space.

[0046] As one possible implementation method, the backup and restore device installs an operating system in the first storage space of the target device and creates a subvolume to be backed up corresponding to the file to be backed up in the operating system of the target device, including: if the file type of the file to be backed up can be changed to a btrfs file type, then the changed file to be backed up is determined as the subvolume to be backed up; if the file type of the file to be backed up cannot be changed to a btrfs file type, then an empty subvolume is created in the default mount directory of the operating system, and the contents of the file to be backed up are copied into the empty subvolume to obtain the subvolume to be backed up corresponding to the file to be backed up.

[0047] For example, such as Figure 3 As shown, the backup and restore device, based on a preprocessing module, uses a kickstart file to automatically install the operating system in the first storage space of the target device. (The kickstart file can be stored on a single server and read by an independent machine during the installation process, providing users with an automated method for installing the Linux operating system.) During the installation, the Security-Enhanced Linux (SELinux) system is disabled. After the operating system installation is complete, post-installation processing is performed to determine the files to be backed up and to create the corresponding sub-volumes for backup within the operating system of the target device. If the file type of the files to be backed up can be directly changed to btrfs, such as / var or / log files, the backup and restore device will change the file type of / var, / log, and other files that can be directly changed to btrfs, thus obtaining the corresponding sub-volumes to be backed up, such as var and log sub-volumes.

[0048] If the file type of the file to be backed up cannot be changed to btrfs, for example, the / etc file cannot be directly changed to btrfs, meaning the etc subvolume cannot be directly obtained, then in the post-processing, the backup and restore device mounts the target device where the operating system resides to the / mount (mnt) directory and enters the / mnt directory (the / mnt directory is a directory used to mount external devices; after mounting, the target device where the operating system resides can be accessed through this directory). In this directory, the backup and restore device creates an empty file, changes the type of this empty file to btrfs, and obtains an empty subvolume. The contents of the file to be backed up, which cannot be directly changed to btrfs, are copied into the empty subvolume, thus obtaining the subvolume corresponding to the file to be backed up.

[0049] For example, the backup and restore device creates an empty file in the / mnt directory, changes the file type of this empty file to btrfs, resulting in an empty subvolume. The contents of the file to be backed up, / etc, are copied into this empty subvolume, thus transforming the empty volume into the / etc subvolume. In other words, the / etc subvolume corresponding to the file to be backed up is successfully created. After the subvolume corresponding to the file to be backed up is successfully created, the backup and restore device exits the / mnt directory, unmounts the target device where the operating system resides, and deletes all contents of the file to be backed up. This prevents the operating system from booting with an incorrect configuration in case of mount failure. For example, the backup and restore device enters the / mnt directory, completes the creation of the / etc subvolume corresponding to the file to be backed up, exits the / mnt directory, and deletes all contents of the / etc file.

[0050] S202. In response to the backup command for the operating system, generate a first mount point and mount the target device to the first mount point.

[0051] As one possible approach, the backup and restore device responds to the user's mount command for the operating system by mounting the subvolume to be backed up to a second mount point (and using the second mount point as the restore path), that is, mounting the subvolume corresponding to the file to be backed up to the corresponding directory, thus completing the preparation work for the backup and restore operation; after the preparation work for the backup and restore operation is completed, the backup and restore device responds to the user's backup command for the operating system by generating a first mount point and mounting the target device to the first mount point, that is, generating a temporary directory in the operating system and mounting the target device where the operating system is located to the temporary directory.

[0052] For example, such as Figure 3 As shown, the backup and restore device, based on the subvolume mounting module, responds to the user's mount command to the operating system by mounting the subvolume to be backed up to the second mount point (the second mount point is the directory corresponding to each subvolume to be backed up when the backup and restore device mounts each subvolume to be backed up; for example, the second mount point for the / etc subvolume is the directory / sysroot / etc corresponding to the / etc subvolume when it is mounted). In other words, the subvolume to be backed up is mounted to the specified directory corresponding to each subvolume to be backed up, completing the mounting operation. For example, during the operating system restart process, the backup and restore device installs the subvolume mounting module. For the / etc subvolume corresponding to the file to be backed up, the auxiliary system (Initial RAM Filesystem, initramfs) stores the code that calls the subvolume mounting module based on the memory file system, guiding the completion of the mounting operation for the / etc file.

[0053] The specific mount operations include: In the subvolume mount module, in response to user mount commands to the operating system, the backup and restore device first installs hook functions via module-setup.sh, and then instructs the backup and restore device to perform the specific operations (mounting the / etc file) during the pre-pivot phase via etc-hook.sh; the backup and restore device then performs the mount operation on the file to be backed up, including: responding to user mount commands to the operating system, i.e., based on the program code set during hook installation and implementation, completing the mount operation on the specified file to be backed up; for example, etc-hook. The `sh` command instructs the backup and restore device to mount the ` / etc` file. Specifically, it mounts the subvolume ` / etc` corresponding to the file to be backed up to the directory ` / sysroot / etc` corresponding to the ` / etc` subvolume. Here, `sysroot` specifies the system root directory location, used to correctly locate the required file and mount the subvolume to the corresponding directory. Only the directory name after ` / sysroot` needs to be changed; for example, the ` / etc` subvolume corresponds to ` / sysroot / etc`, the ` / var` subvolume to ` / sysroot / var`, and the ` / log` subvolume to ` / sysroot / log`, etc.

[0054] In the subvolume mounting module, if the backup and restore device has completed one or more restore operations, before mounting the subvolume corresponding to the file to be backed up to the corresponding directory, it is necessary to delete the abandoned subvolumes generated during the restore operation. For example, the backup and restore device first mounts the target device where the operating system is located to the / sysroot / mnt / directory, enters the directory, and uses the btrfs command in the directory to delete abandoned subvolumes, that is, all abandoned subvolumes marked as abandoned (drop) in the folder with the suffix .drop. After the backup and restore device deletes the abandoned subvolumes, it exits the / sysroot / mnt / directory and unmounts the target device, thus completing the processing of abandoned subvolumes.

[0055] After the backup and restore device mounts the subvolume to be backed up to the second mount point, that is, mounts the subvolume corresponding to the files to be backed up to the corresponding directory, the preparation work for the backup and restore operation is completed. When the backup operation begins, the backup and restore device responds to the user's backup command for the operating system, generates a first mount point (the first mount point is a temporary directory generated in the operating system when the backup and restore device begins the backup operation, used to support the backup and restore device to complete the backup operation at this mount point), and mounts the target device to the first mount point. Specifically, the backup and restore device mounts the target device to the first mount point, including: such as Figure 3As shown, the backup and restore device responds to the user's backup command for the operating system and starts the backup operation of the file to be backed up based on the backup and restore module. First, a temporary directory is generated in the operating system, the target device where the operating system is located is mounted to the temporary directory, and the device enters the temporary directory for subsequent backup operations of the sub-volume corresponding to the file to be backed up in the temporary directory.

[0056] S203. Perform a backup operation on the subvolume to be backed up at the first mount point to obtain a snapshot of the subvolume to be backed up.

[0057] As one possible approach, the backup and restore device performs a backup operation on the subvolume to be backed up at the first mount point, obtaining a snapshot corresponding to the subvolume to be backed up (the snapshot can be a new subvolume obtained after backing up the subvolume to be backed up). That is, the backup and restore device mounts the target device where the operating system is located to a temporary directory, enters the temporary directory, determines the subvolume to be backed up corresponding to the file to be backed up, as well as the name of the snapshot after backing up the subvolume to be backed up, and completes the backup operation based on the user's backup command for the operating system, obtaining a snapshot corresponding to the subvolume to be backed up.

[0058] For example, the backup and restore module includes backup scripts and restore scripts, such as... Figure 4 As shown, in the backup and restore module, the backup and restore device receives parameters passed from the command line based on the backup script. Required parameters include critical files to be backed up, i.e., all files to be backed up. Optional parameters include specifying the names of the files to be backed up. The backup and restore device generates a temporary directory in the operating system. After mounting the target device where the operating system resides to this temporary directory, it enters the temporary directory. First, based on the parameters received from the backup script, it determines whether a name for the files to be backed up has been specified. If a name is specified, the specified name is used as the name of the sub-volume corresponding to the file to be backed up, and the name of the snapshot after the backup. If no name is specified, the time when the file to be backed up was used as the name of the sub-volume corresponding to the file to be backed up, and the name of the snapshot after the backup.

[0059] Then, the backup and restore device checks whether the file to be backed up with the specified name exists. If it exists, it performs a backup operation on the file to be backed up and obtains a snapshot of the file to be backed up. If it does not exist, it prompts "unknown backupfile" (the backup file does not exist, that is, the snapshot does not exist) and performs a backup operation on all the critical files that need to be backed up, which are included in the required parameters received by the backup script, and obtains a snapshot of each critical file that needs to be backed up. For example, if the file to be backed up is the / etc file, the backup and restore device has already mounted the / etc subvolume corresponding to the / etc file to the corresponding / sysroot / etc directory. A temporary directory is generated in the operating system, and the target device where the operating system is located is mounted to this temporary directory. Entering this temporary directory, the program code backup -f / etc-name bak determines the name of the snapshot after the backup of the / etc subvolume (the code indicates that the file to be backed up is the / etc file, and the name of the snapshot after the backup is / etc-bak). The backup and restore device determines that the file to be backed up is the / etc file, and executes the backup command btrfs subvolume snapshot etc etc-bak to complete the backup operation. That is, the btrfs command is used to back up the / etc subvolume corresponding to the / etc file, and a snapshot named etc-bak is obtained.

[0060] S204. Create a preset file in the second storage space and store the snapshot in the preset file.

[0061] The second storage space is located in the target device.

[0062] As one possible implementation, the backup and restore device creates a preset file in the second storage space of the target device. This preset file is a folder used to store snapshots corresponding to all sub-volumes to be backed up. After the backup and restore device performs a backup operation on the sub-volume to be backed up and obtains the snapshots corresponding to the sub-volume to be backed up, it stores all the snapshots corresponding to the sub-volume to be backed up into this folder.

[0063] S205. Uninstall the target device and delete the first mount point to complete the backup operation.

[0064] As one possible approach, the backup and restore device performs a backup operation on the subvolume to be backed up, obtains a snapshot of the subvolume to be backed up, and stores the snapshot in a preset file in the second storage space. Then, it unmounts the target device where the preset file storing the snapshot is located and deletes the first mount point, i.e., deletes the temporary directory created at the start of the backup operation, thus completing the backup operation.

[0065] S206. In response to the restore command for the operating system, restore the contents of the snapshot to be restored to the operating system, and complete the restore operation.

[0066] One possible implementation is that, in response to a user's restore command to the operating system, the backup and restore device generates a third mount point (a temporary directory created in the operating system when the backup and restore device begins the restore operation, used to support the restore operation at this mount point), and mounts the target device to the third mount point. This involves creating a temporary directory in the operating system and mounting the target device containing the preset snapshot file to this temporary directory. The backup and restore device first determines the snapshot to be restored (i.e., the file to be restored), then determines the subvolume corresponding to the file (the subvolume to be backed up), and uses the snapshot corresponding to the subvolume as the snapshot to be restored. The restore operation is performed on the snapshot to be restored at the third mount point. The snapshot to be restored is then sent to the second mount point, and the subvolume to be backed up is deleted from the second mount point. In other words, in the temporary directory, the restore command is executed, sending the snapshot to be restored to the directory containing the corresponding subvolume, and the corresponding subvolume is deleted. After completing the above operations, the backup and restore device unmounts the target device and deletes the third mount point (deleting the temporary directory generated for the restore operation), thus completing the restore operation.

[0067] For example, such as Figure 4 As shown, in response to the user's restore command to the operating system, the backup and restore device generates a temporary directory in the operating system, mounts the target device containing the preset file for storing snapshots to this temporary directory, and enters the temporary directory. After entering the temporary directory, the backup and restore device determines the file to be restored based on the parameters passed from the command line to the restore script (the parameters include the critical file to be restored and the snapshot to be restored), then determines the subvolume corresponding to the file to be restored (i.e., the subvolume to be backed up when the file is used as the file to be backed up), and checks whether there is a snapshot corresponding to the subvolume corresponding to the file to be restored in the preset file of the second storage space of the target device (the folder used to store all snapshots). If no snapshot exists for the subvolume corresponding to the file to be restored, the message "unknown backupfile" will be displayed, indicating that the snapshot for the file to be restored does not exist. If a snapshot exists for the subvolume corresponding to the file to be restored, the original volume will be marked as "dropped," and a restore operation will be performed. Specifically, this snapshot will be identified as the snapshot to be restored, and the snapshot to be restored will be sent to the directory where the corresponding subvolume is located. In other words, the backup and restore device will restore the contents of the snapshot to be restored to the operating system. The contents of the snapshot to be restored are all the contents of the file to be backed up. For example, if the snapshot to be restored is etc-bak, then the contents of this snapshot are all the contents of the / etc file.

[0068] After the backup and restore device sends the snapshot to be restored to the directory where the corresponding subvolume is located, it replaces the original volume in that directory by marking the original volume as "drop" and moving it to a folder with the ".drop" extension (this folder contains all subvolumes marked as "drop," and is located in the third storage space of the target device; the abandoned subvolumes in this folder will be deleted during the process of restarting the operating system and reinstalling the mount module). After completing the above operations, the backup and restore device unmounts the target device and deletes the third mount point (deleting the temporary directory generated above for performing the restore operation), thus completing the restore operation.

[0069] For example, in response to a user's restore command to the operating system, the backup and restore device generates a temporary directory in the operating system, mounts the target device containing the preset file storing the snapshot to this temporary directory, and enters the temporary directory. After entering the temporary directory, the backup and restore device determines that the file to be restored is the / etc file, executes the command `restore -f / etc -s etc-bak`, and determines the snapshot / etc-bak corresponding to the / etc subvolume corresponding to the / etc file from the folder used to store all snapshots. The backup and restore device executes the restore command `btrfs subvolume snapshot etc-bak etc` to restore the snapshot / etc-bak; that is, it uses the `btrfs` command to replace the / etc subvolume with the snapshot / etc-bak. Specifically, since the backup and restore device mounts the / etc subvolume to the / sysroot / etc directory in the subvolume mounting module, the snapshot / etc-bak to be restored is moved to the / sysroot / etc directory, and the original / etc subvolume located in the / sysroot / etc directory is marked as drop and moved to a folder with the .drop extension in the target device's third-party storage space. When restarting the operating system and reinstalling the mount module, if you want to mount the new backup file to the corresponding directory, you need to first delete the etc subvolume in the folder with the .drop extension in the target device's third-party storage space. After the backup and restore device completes the operation of replacing the atomic volume with the snapshot to be restored, it unmounts the target device where the preset file of the storage snapshot is located and deletes the temporary directory generated for performing the restore operation, thus completing the restore operation.

[0070] Understandable, such as Figure 5 As shown, the backup and restore device, based on a preprocessing module and using a kickstart file, automatically installs the operating system in the first storage space of the target device. During each operating system reboot, it installs a sub-volume mount module and, in response to user mount commands for the operating system, calls the sub-volume mount module's code based on initramfs to mount the files to be backed up. After the mount operation is complete, a backup or restore operation is performed.

[0071] Specifically, the backup and restore device installs the operating system in the first storage space of the target device, creates a subvolume containing the files to be backed up. If the file type of the file to be backed up can be changed to btrfs, the modified file is designated as the subvolume to be backed up. If the file type of the file to be backed up cannot be changed to btrfs, the target device containing the operating system is mounted to the / mnt directory. Inside the / mnt directory, an empty file is created, and its type is changed to btrfs, resulting in an empty subvolume. The contents of the file to be backed up are then copied into this empty subvolume, creating the subvolume corresponding to the file to be backed up. After the subvolume is created, the backup and restore device responds to the user's mount command for the operating system, and based on initramfs, calls the subvolume mount module code to mount the subvolume to be backed up to the corresponding directory, completing the mount operation.

[0072] After the mounting operation is completed, the backup and restore device responds to the user's backup command for the operating system, generates a temporary directory in the operating system, mounts the target device where the operating system resides to this temporary directory, and enters the temporary directory. In this temporary directory, based on the parameters received by the backup script, it first determines whether a name for the file to be backed up has been specified. If a name for the file to be backed up has been specified, the specified name is used as the name of the sub-volume to be backed up and the name of the snapshot after the backup. If no name for the file to be backed up has been specified, the time when the file to be backed up was used as the name of the sub-volume to be backed up and the name of the snapshot after the backup. After determining the snapshot name corresponding to the sub-volume to be backed up, it determines whether the file to be backed up exists. Then, after determining the file to be backed up, it performs a backup operation on the sub-volume to be backed up, obtaining a snapshot corresponding to the sub-volume to be backed up. A folder for storing snapshots is created in the second storage space of the target device, and the snapshot corresponding to the sub-volume to be backed up obtained above is stored in this folder. After storage is completed, the target device is unmounted, and the temporary directory generated for performing the backup operation is deleted, completing the backup operation.

[0073] In response to a user's restore command to the operating system, the backup and restore device generates a temporary directory in the operating system, mounts the target device containing the snapshot folder to this temporary directory, and enters the temporary directory. Within this temporary directory, it checks whether a snapshot corresponding to the subvolume containing the file to be restored exists. Once the snapshot to be restored is identified, it performs a restore operation, sending the snapshot to be restored to the directory containing the corresponding subvolume, replacing the original volume in that directory, marking the original volume as "drop," and moving it to a folder with the .drop extension in the target device's third-party storage. After the replacement operation is complete, it unmounts the target device and deletes the temporary directory generated for the restore operation, thus completing the restore operation.

[0074] The technical solution provided in this application provides at least the following beneficial effects: The backup and restore device creates a sub-volume corresponding to the file to be backed up in the operating system of the target device; the target device includes a first storage space and a second storage space, and the operating system is located in the first storage space. This application creates a sub-volume corresponding to the file to be backed up in the operating system of the target device, solving the problem that special files cannot be made into sub-volumes and cannot be quickly backed up in conjunction with snapshot operations, enabling the backup and restore device to perform separate backup and restore of special files. In response to a backup command for the operating system, the backup and restore device generates a first mount point and mounts the target device to the first mount point; performs a backup operation on the sub-volume to be backed up in the first mount point to obtain a snapshot corresponding to the sub-volume to be backed up; creates a preset file in the second storage space and stores the snapshot in the preset file; unmounts the target device and deletes the first mount point to complete the backup operation. Compared to existing technologies where skilled personnel use additional storage devices to perform backup and restore operations, this application uses a simple and easy-to-use script to create subvolumes corresponding to the files to be backed up via the btrfs file system. Then, it combines the snapshot function to achieve backup of files or important data. This does not require connecting to a storage device, the process is simpler, and the combination of snapshot function reduces the time spent on backup, thus improving backup efficiency.

[0075] The above embodiments mainly describe the solutions provided by the embodiments of this application from the perspective of an apparatus (device). It is understood that, in order to implement the above methods, the apparatus or device includes hardware structures and / or software modules corresponding to the execution of each method flow. These hardware structures and / or software modules corresponding to the execution of each method flow can constitute a material information determination apparatus. Those skilled in the art should readily recognize that, in conjunction with the algorithm steps of the various examples described in the embodiments of the invention herein, this application can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed in a hardware or computer software-driven hardware manner depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0076] This application embodiment can divide the device or equipment into functional modules according to the above method examples. For example, the device or equipment can be divided into functional modules corresponding to each function, or two or more functions can be integrated into one processing module. The integrated module can be implemented in hardware or as a software functional module. It should be noted that the module division in this application embodiment is illustrative and only represents one logical functional division. In actual implementation, there may be other division methods.

[0077] Figure 6 This is a schematic diagram illustrating the structure of a backup and restore device according to an exemplary embodiment. (Refer to...) Figure 6 As shown, the backup and restore device 30 provided in this application embodiment includes a creation unit 301, a processing unit 302, a backup unit 303, and an unloading unit 304.

[0078] Creation unit 301 is used to create a sub-volume to be backed up corresponding to the file to be backed up in the operating system of the target device; the target device includes a first storage space and a second storage space, and the operating system is located in the first storage space; processing unit 302 is also used to generate a first mount point in response to the backup command of the operating system, and mount the target device to the first mount point; backup unit 303 is also used to perform a backup operation on the sub-volume to be backed up in the first mount point to obtain a snapshot corresponding to the sub-volume to be backed up; creation unit 301 is also used to create a preset file in the second storage space and store the snapshot in the preset file; unmount unit 304 is also used to unmount the target device and delete the first mount point to complete the backup operation.

[0079] Optionally, the processing unit 302 is specifically used to: in response to the mount command of the operating system, mount the subvolume to be backed up to the second mount point, and use the second mount point as the restore path.

[0080] Optionally, the processing unit 302 is specifically configured to: generate a third mount point in response to a restore command for the operating system, and mount the target device to the third mount point; take the snapshot corresponding to the subvolume to be backed up as the snapshot to be restored, perform a restore operation on the snapshot to be restored in the third mount point, send the snapshot to be restored to the second mount point, and delete the subvolume to be backed up in the second mount point; unmount the target device, delete the third mount point, and complete the restore operation.

[0081] Optionally, the processing unit 302 is specifically used for: if the file type of the file to be backed up can be changed to the btrfs file type, then the changed file to be backed up is determined as the subvolume to be backed up; if the file type of the file to be backed up cannot be changed to the btrfs file type, then an empty subvolume is created in the operating system's default mount directory, and the contents of the file to be backed up are copied into the empty subvolume to obtain the subvolume to be backed up corresponding to the file to be backed up.

[0082] Figure 7 This is a schematic diagram of the structure of an electronic device provided in this application. For example... Figure 7 The electronic device 40 may include at least one processor 401 and a memory 402 for storing processor-executable instructions, wherein the processor 401 is configured to execute the instructions in the memory 402 to implement the operating system backup and restore method in the above embodiments.

[0083] In addition, the electronic device 40 may also include a communication bus 403 and at least one communication interface 404.

[0084] Processor 401 may be a processor (central processing unit, CPU), microprocessor unit, ASIC, or one or more integrated circuits for controlling the execution of programs according to the present application.

[0085] The communication bus 403 may include a path for transmitting information between the aforementioned components.

[0086] Communication interface 404 uses any transceiver-like device for communicating with other devices or communication networks, such as Ethernet, radio access network (RAN), wireless local area networks (WLAN), etc.

[0087] The memory 402 may be a read-only memory (ROM) or other type of static storage device capable of storing static information and instructions, random access memory (RAM) or other type of dynamic storage device capable of storing information and instructions, or electrically erasable programmable read-only memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital versatile optical discs, Blu-ray discs, etc.), magnetic disk storage media or other magnetic storage devices, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but not limited thereto. The memory may exist independently and be connected to the processor 401 via a bus. The memory may also be integrated with the processor 401.

[0088] The memory 402 stores instructions for executing the scheme of this application, and the processor 401 controls the execution. The processor 401 executes the instructions stored in the memory 402 to realize the functions of the method of this application.

[0089] As an example, combined Figure 6 The functions implemented by the creation unit 301, processing unit 302, backup unit 303, and unloading unit 304 in the backup and restore device 30 are the same as those of the backup and restore device 30. Figure 7 The processor 401 in it has the same function.

[0090] In a specific implementation, as one example, processor 401 may include one or more CPUs, for example... Figure 7 CPU0 and CPU1 in the CPU.

[0091] In a specific implementation, as one example, the electronic device 40 may include multiple processors, such as... Figure 7 Processors 401 and 407 are described herein. Each of these processors may be a single-core (single-CPU) processor or a multi-core (multi-CPU) processor. A processor here may refer to one or more devices, circuits, and / or processing cores used to process data (e.g., computer program instructions).

[0092] In a specific implementation, as one embodiment, the electronic device 40 may further include an output device 405 and an input device 406. The output device 405 communicates with the processor 401 and can display information in various ways. For example, the output device 405 may be a liquid crystal display (LCD), a light-emitting diode (LED) display device, a cathode ray tube (CRT) display device, or a projector, etc. The input device 406 communicates with the processor 401 and can accept input from user objects in various ways. For example, the input device 406 may be a mouse, keyboard, touchscreen device, or sensing device, etc.

[0093] Those skilled in the art will understand that Figure 7 The structure shown does not constitute a limitation on the electronic device 40, and may include more or fewer components than shown, or combine certain components, or use different component arrangements.

[0094] In addition, this application also provides a computer-readable storage medium that, when the instructions in the computer-readable storage medium are executed by the processor of an electronic device, enables the electronic device to perform the backup and restore method of the operating system provided in the above embodiments.

[0095] In addition, this application also provides a computer program product, including computer instructions, which, when executed on an electronic device, cause the electronic device to perform the backup and restore method of the operating system as provided in the above embodiments.

[0096] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention described herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not invented herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the claims.

Claims

1. A method for backing up and restoring an operating system, characterized in that, The method includes: Create a subvolume corresponding to the file to be backed up in the operating system of the target device; the target device includes a first storage space and a second storage space, and the operating system is located in the first storage space; Creating the subvolume to be backed up corresponding to the files to be backed up in the operating system of the target device includes: If the file type of the file to be backed up can be changed to btrfs file type, then the changed file to be backed up will be identified as the subvolume to be backed up. If the file type of the file to be backed up cannot be changed to the btrfs file type, then an empty subvolume is created in the default mount directory of the operating system, and the contents of the file to be backed up are copied into the empty subvolume to obtain the subvolume to be backed up corresponding to the file to be backed up. In response to the backup command for the operating system, a first mount point is generated, and the target device is mounted to the first mount point; Perform a backup operation on the subvolume to be backed up at the first mount point to obtain a snapshot of the subvolume to be backed up. Create a preset file in the second storage space, and store the snapshot in the preset file; Uninstall the target device and delete the first mount point to complete the backup operation.

2. The method according to claim 1, characterized in that, The method further includes: In response to the mount command for the operating system, the subvolume to be backed up is mounted to the second mount point, and the second mount point is used as the restore path.

3. The method according to claim 2, characterized in that, The method further includes: In response to the restore command for the operating system, a third mount point is generated, and the target device is mounted to the third mount point; The snapshot corresponding to the subvolume to be backed up is taken as the snapshot to be restored. The snapshot to be restored is restored in the third mount point. The snapshot to be restored is sent to the second mount point, and the subvolume to be backed up in the second mount point is deleted. Uninstall the target device and delete the third mount point to complete the restore operation.

4. A backup and restore device for an operating system, characterized in that, The backup and restore device includes a creation unit, a processing unit, a backup unit, and an uninstallation unit; The creation unit is used to create a subvolume to be backed up corresponding to the file to be backed up in the operating system of the target device; The target device includes a first storage space and a second storage space, and the operating system is located in the first storage space; the creation unit is specifically used to determine the modified file to be backed up as a subvolume to be backed up if the file type of the file to be backed up can be changed to a btrfs file type; if the file type of the file to be backed up cannot be changed to a btrfs file type, an empty subvolume is created in the preset mount directory of the operating system, and the contents of the file to be backed up are copied into the empty subvolume to obtain the subvolume to be backed up corresponding to the file to be backed up; The processing unit is further configured to, in response to a backup command for the operating system, generate a first mount point and mount the target device to the first mount point; The backup unit is also used to perform a backup operation on the subvolume to be backed up at the first mount point to obtain a snapshot corresponding to the subvolume to be backed up. The creation unit is further configured to create a preset file in the second storage space and store the snapshot in the preset file; The unloading unit is also used to unload the target device and delete the first mount point to complete the backup operation.

5. The backup and restore device according to claim 4, characterized in that, The processing unit is specifically configured to: in response to the mount command of the operating system, mount the subvolume to be backed up to the second mount point, and use the second mount point as the restore path.

6. The backup and restore device according to claim 5, characterized in that, The processing unit is specifically configured to: in response to the restore command of the operating system, generate a third mount point and mount the target device to the third mount point; take the snapshot corresponding to the subvolume to be backed up as the snapshot to be restored, perform a restore operation on the snapshot to be restored in the third mount point, send the snapshot to be restored to the second mount point, and delete the subvolume to be backed up in the second mount point; Uninstall the target device and delete the third mount point to complete the restore operation.

7. An electronic device, characterized in that, include: A processor and a memory for storing instructions executable by the processor; wherein the processor is configured to execute instructions to implement the backup and restore method of the operating system according to any one of claims 1-3.

8. A computer-readable storage medium storing instructions thereon, characterized in that, When the instructions in the computer-readable storage medium are executed by the processor of the electronic device, the electronic device is able to perform the backup and restore method of the operating system as described in any one of claims 1-3.

Citation Information

Patent Citations

  • Backup restoration method and system of operating system

    CN114138560A