File backup and recovery method, device, storage medium and computer program product

By generating automated backup and recovery scripts in white-box switches and utilizing the MD5 checksum mechanism, the problem of easily lost configuration files during white-box switch system upgrades is solved, achieving automated file backup and recovery, reducing the risk of data loss and improving the system's flexibility and scalability.

CN122137834APending Publication Date: 2026-06-02CHINA MOBILE (SUZHOU) SOFTWARE TECH CO LTD +1

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
CHINA MOBILE (SUZHOU) SOFTWARE TECH CO LTD
Filing Date
2026-02-02
Publication Date
2026-06-02

AI Technical Summary

Technical Problem

In the SONiC operating system for white-box switches, during system upgrades and software package replacements, existing technologies rely on manual configuration or external components, which makes file saving and recovery functions prone to failure. Furthermore, core files may be reset after the new installation package is installed, resulting in the loss of configuration data.

Method used

By obtaining the configuration file path information of network devices, an automated backup script is generated to back up the configuration files to a shared directory and automatically restore them to the original path after a system update. The MD5 verification mechanism is used to ensure data integrity and reduce dependence on external components.

Benefits of technology

It enables automated backup and recovery of configuration files without relying on external components, reducing the risk of configuration data loss, minimizing manual intervention and maintenance costs, and supporting seamless switching and scalability of network devices across different systems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122137834A_ABST
    Figure CN122137834A_ABST
Patent Text Reader

Abstract

This application provides a file backup and recovery method, device, storage medium, and computer program product. The method includes: obtaining the path information of the configuration file to be migrated corresponding to the network device, and generating a backup script based on the path information; and backing up the configuration file under the path information to a shared directory for recording configuration files set on the network device based on the backup script.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data migration technology, and in particular to a file backup and recovery method, device, storage medium, and computer program product. Background Technology

[0002] In the SONiC operating system for white-box switches, system upgrades and software package replacements typically require the backup and recovery of a large number of critical files and configuration data. However, traditional file migration methods often rely on manual configuration or external components. If external components fail, the file saving and recovery functions may become unusable. Alternatively, in some solutions, core files may be reset after a new installation package is installed, which can easily lead to the loss of configuration data. Summary of the Invention

[0003] In view of this, this application aims to provide a file backup and recovery method, device, storage medium, and computer program product that can reduce the risk of configuration data loss.

[0004] The technical solution of this application is implemented as follows: In a first aspect, this application provides a file backup method, the method comprising: Obtain the path information of the configuration file to be migrated for the network device, and generate a backup script based on the path information; Based on the backup script, the configuration files under the path information are backed up to the shared directory for recording configuration files set on the network device.

[0005] Secondly, this application provides a file recovery method, the method comprising: Obtain the path information of the configuration file to be migrated for the network device, and generate a recovery script based on the path information; Based on the recovery script, the configuration file backed up to the shared directory of the record configuration file set on the network device is restored to the path information corresponding to the configuration file.

[0006] Thirdly, this application provides a file backup device, the file backup device comprising: The first determining unit is used to obtain the path information of the configuration file to be migrated corresponding to the network device, and generate a backup script based on the path information; The backup unit is used to back up the configuration files under the path information to the shared directory of the record configuration files set on the network device, based on the backup script.

[0007] Fourthly, this application provides a file recovery device, the file recovery device comprising: The second determining unit is used to obtain the path information of the configuration file to be migrated corresponding to the network device, and generate a recovery script based on the path information; The recovery unit is used to restore the configuration files backed up to the shared directory of the record configuration files set on the network device to the path information corresponding to the configuration files, based on the recovery script.

[0008] Fifthly, this application provides an electronic device, the electronic device comprising: a processor and a memory; the processor implements the above-described file backup method when executing a running program stored in the memory, or the processor implements the above-described file recovery method when executing a running program stored in the memory.

[0009] Sixthly, this application provides a storage medium storing a computer program thereon, which, when executed by a processor, implements the above-described file backup method, or, when executed by a processor, implements the above-described file recovery method.

[0010] Seventhly, this application provides a computer program product, including a computer program that, when executed by a processor, implements the above-described file backup method, or, when executed by a processor, implements the above-described file recovery method.

[0011] This application provides a file backup and recovery method, device, storage medium, and computer program product. The method includes: obtaining the path information of the configuration file to be migrated corresponding to the network device, and generating a backup script based on the path information; and backing up the configuration file under the path information to a shared directory set on the network device for recording configuration files based on the backup script. By adopting the above implementation scheme, by obtaining the path information of the configuration file to be migrated and generating an automated backup script based on the path information, the configuration file is automatically backed up to the shared directory of the network device during configuration file backup. This not only reduces dependence on external components, but also ensures that the shared directory is located within the network device and is independent of the network device's installation package, thus preventing it from being reset due to updates to the installation package on the network device. This reduces the risk of configuration data loss. Attached Figure Description

[0012] Figure 1 A flowchart illustrating a file backup method provided in an embodiment of this application; Figure 2 A flowchart illustrating a file recovery method provided in an embodiment of this application; Figure 3 This is a schematic diagram of the overall process of a file backup and recovery method provided in an embodiment of this application; Figure 4This is a schematic diagram of the composition structure of a file backup device provided in an embodiment of this application; Figure 5 This is a schematic diagram of the composition structure of a file recovery device provided in an embodiment of this application; Figure 6 This is a schematic diagram of the composition structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0013] To gain a more detailed understanding of the features and technical content of the embodiments of this application, the technical solution of this application will be further described in detail below with reference to the accompanying drawings and specific embodiments. The accompanying drawings are for reference only and are not intended to limit the embodiments of this application.

[0014] Unless otherwise defined, all technical and scientific terms used in the embodiments of this application have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used in the embodiments of this application is for the purpose of describing the embodiments of this application only and is not intended to limit this application.

[0015] In the following description, references to "some embodiments" refer to a subset of all possible embodiments. It is understood that "some embodiments" may be the same or different subsets of all possible embodiments and may be combined with each other without conflict. It should also be noted that the terms "first / second / third" used in the embodiments of this application are merely for distinguishing similar objects and do not represent a specific ordering of objects. It is understood that "first / second / third" may be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein.

[0016] When saving and restoring files during a system upgrade of a switch (white-box switch), the common methods include the following two: Method 1: When backing up the configuration file, the switch determines whether to start the Baseboard Management Controller (BMC) backup. If the BMC backup is started, the configuration file is saved to the switch and transmitted to the BMC at the same time. The BMC checks whether the configuration file saved in the switch has changed every threshold time interval. If it has changed, the BMC copies the changed configuration file to the BMC. If the switch is restarting for the first time after reinstalling or updating the network operating system, the switch obtains the latest saved configuration file from the BMC to complete the switch restoration.

[0017] Method 2: The configuration distribution module receives user-issued instructions to modify critical file information and updates the corresponding SYS_FILE information in the database based on these instructions; a monitoring module creates the SYS_FILE table in the database. This solution, combined with the characteristics of white-box switch systems, proposes a method and device for protecting and restoring critical files on white-box switches. It mainly achieves critical file protection and restoration for data center switches through a configuration distribution module, an execution module, and a monitoring module. All modules in this method are deployed on the switch. After service startup, critical files are saved in an independent disk partition for protection. During system startup, these files are checked and restored, thus ensuring that critical files are not corrupted or tampered with during startup.

[0018] The first method focuses on using the BMC (Browser Control Center) for file saving and recovery. When the BMC fails, these functions will fail, resulting in high coupling. The second method, a critical file protection and recovery method for white-box switches, records the files to be protected in a database and creates a separate partition for backup. Since the database resides on the operating system, storing critical files on the operating system's database means that any system update will also erase that database. Therefore, changing the operating system will result in both the partition and the saved files being lost.

[0019] Therefore, in the SONiC operating system for white-box switches, system upgrades and software package replacements typically require the backup and recovery of a large amount of critical files and configuration data. However, some technical solutions employed in this field may still face the following technical challenges: Some migration methods often only cover partial system configurations, failing to cover sensitive system data such as system users. Furthermore, numerous configuration files require manual backup and recovery, especially in white-box switch SONiC operating systems where multiple systems share a single file system. Some core files are reset after a new installation package is installed, leading to data loss or loss of user configurations. The mechanisms in related technologies that use automated scripts to back up and migrate configurations and critical files have limitations and cannot meet all the needs of practical applications.

[0020] To address the aforementioned issues, this application provides a file backup method that not only enables file saving and recovery from the switch without relying on the BMC (Block Controller) or any external components, but also allows for the saving and recovery of critical files in scenarios requiring operating system replacement. The file backup method is as follows: Figure 1 As shown, the method may include: S101. Obtain the path information of the configuration file to be migrated corresponding to the network device, and generate a backup script based on the path information.

[0021] In this embodiment, the network device may include a white-box switch, which may be a switch that supports multiple systems.

[0022] In this embodiment of the application, the configuration file to be migrated may be a configuration file that needs to be backed up, wherein the configuration file includes system-related configurations, system users and other sensitive system data.

[0023] It should be noted that the configuration file can be any configuration file in the white-box switch that needs to be backed up. Specifically, it can be selected according to the actual situation, and no specific limitation is made in this embodiment.

[0024] In this embodiment, the path information can be the location of the configuration file, a relative path, or an absolute path. The specific path can be selected according to the actual situation, and no specific limitation is made in this embodiment.

[0025] In one embodiment of this application, the path information of the configuration file to be migrated corresponding to the network device can be obtained in the following way: the path information of all configuration files to be migrated in the network device is pre-recorded in the file path set; when the system of the network device is updated, the file path set is parsed to obtain the path information.

[0026] In this embodiment of the application, the concept of a path set is introduced, which is represented by P. This indicates the paths of all files that need to be migrated in the white-box switch system.

[0027] In this embodiment, the white-box switch operating system can pre-record the file paths corresponding to all configuration files that need to be backed up in the white-box switch system in a file path set P. Specifically, the system dynamically records the set P in / etc / sonic / config_db.json through the migration_files field to form a file path set P, which can be represented by the following formula (1): (1) Where P represents the set of file paths, Let i represent the path of the i-th file to be migrated, where i = 1, 2, 3, ..., i.

[0028] It should be noted that the file path set can also be represented by other letters or symbols. Specifically, it can be selected according to the actual situation, and this application embodiment does not make specific limitations.

[0029] In this embodiment, after recording the path information corresponding to all configuration files that need to be backed up in the file path set P, since the file path set P is recorded in / etc / sonic / config_db.json, when the white-box switch upgrades and updates the installation package, it will execute sonic_installer install. At this time, the system will parse the migration_files field in / etc / sonic / config_db.json to obtain the path information of the configuration files that need to be backed up.

[0030] In this embodiment, a backup script is generated based on the path information of the configuration file to be backed up. Specifically, this can be implemented using an automatic backup script generation function, which can be denoted as: The automatic backup script generation function automatically generates backup scripts based on file paths in the file path set P. Specifically, the file paths parsed from the file path set P are used as input parameters to the automatic backup script generation function, which then outputs the backup script. The generated backup script is placed in migration-pre-hook.d. The backup script can be named bachup.sh. Calling bachup.sh will back up the configuration file to / host / backup.

[0031] The backup script can be understood as program code that automatically backs up configuration files, data, etc.

[0032] S102. Based on the backup script, back up the configuration file under the path information to the shared directory of the record configuration file set on the network device.

[0033] In this embodiment of the application, the shared directory can be the " / host" directory of the white-box switch SONiC.

[0034] In this embodiment, since the / host directory on the white-box switch SONiC is a shared directory for multiple systems, upgrading a single system will not change the / host directory. Considering this, the configuration files under the path information can be backed up to the / host / backup path under the / host directory where the configuration files are recorded, in order to avoid the loss of configuration files due to system updates.

[0035] In this embodiment of the application, the specific backup process, based on the backup script, backs up the configuration file under the path information to the shared directory of the record configuration file set on the network device. This can be achieved in the following way: when the network device system is updated, the backup script is called and executed; based on the backup function in the backup script, the configuration file under the path information is backed up to the shared directory of the record configuration file set on the network device.

[0036] In this embodiment of the application, during the file backup process, the aforementioned automatic backup script generation function is used. Based on this, the function is called during the sonic_installer install phase, generating the backup script backup.sh. Thus, during the system upgrade of the white-box switch, backup.sh is called and executed from migration-pre-hook.d. backup.sh is responsible for backing up the configuration files corresponding to each file path in the P set to / host / backup. The implementation process is to use the backup function encapsulated in backup.sh to back up the configuration files corresponding to each file path in the P set to / host / backup. This backup process can be expressed by the following formula (2): (2) Formula (2) means that the configuration files corresponding to the file paths in the file path set P are moved to / host / backup.

[0037] In this embodiment, the backup function described above can be represented by the following formula (3): (3) Formula (3) means backing up the configuration file corresponding to the i-th file path to be migrated to the i-th file path under the / host / backup path. For example, copy the configuration file under the / a path to / host / backup / a.

[0038] It should be noted that for each path The backup operation is equivalent to... Copy the corresponding configuration file to the / host / backup directory.

[0039] In one embodiment of this application, considering the design of data consistency and integrity, after pre-recording the path information corresponding to all configuration files to be migrated in the network device in the file path set, the configuration files under each path information in the file path set can be encrypted using a preset encryption algorithm to obtain the first encrypted information corresponding to the configuration files under each path information, so as to verify whether the configuration files have been tampered with based on the first encrypted information during the process of restoring the configuration files under each path information.

[0040] In this embodiment, the system dynamically manages the file path set P in config_db.json to ensure that backup and subsequent recovery operations are automatically executed during each upgrade and system switch, avoiding manual intervention. However, to further ensure data consistency and integrity during system switch or upgrade, this embodiment also introduces a Message-Digest Algorithm 5 (MD5) verification mechanism to prevent configuration files from being corrupted or altered for unknown reasons during backup and subsequent recovery.

[0041] The MD5 verification mechanism verifies the integrity of the configuration file to be migrated by comparing the MD5 hash values ​​of the configuration file before and after the backup, further enhancing the reliability of system configuration files and critical data files.

[0042] In this embodiment, the preset encryption algorithm may be the MD5 encryption algorithm.

[0043] It should be noted that other encryption algorithms can also be used. Specifically, the choice can be made according to the actual situation, and no specific limitation is made in the embodiments of this application.

[0044] In this embodiment of the application, during the file backup process, after the system records the file path corresponding to the configuration file to be migrated in the file path set P, it can also generate an MD5 checksum (i.e., the first encrypted information) for each key configuration file under each file path and store it in the / host / backup / checksum.md5 file.

[0045] In this embodiment of the application, during the file backup operation, the system performs backup on each path in the file path set P. Generating MD5 checksums using the MD5 encryption algorithm can be understood as generating MD5 checksums for each configuration file in each path using the MD5 encryption algorithm, denoted as MD5. and will The checksum is stored in the file / host / backup / checksum.md5. The encryption process can be implemented using the following formula (4): (4) in, This indicates the MD5 encryption algorithm.

[0046] In this embodiment, after calculating the corresponding MD5 checksum for each file path using the MD5 encryption algorithm, this MD5 checksum can be used in the subsequent recovery phase. The system reads and verifies the MD5 checksum of the configuration file to be migrated from the ` / host / backup / checksum.md5` file to ensure that the configuration file to be migrated has not been accidentally modified or lost. For example, if the file path of the configuration file to be migrated is ` / a / b`, then the MD5 checksum of the ` / a / b` file path is first calculated using the MD5 encryption algorithm. Then, when restoring the configuration file, the same MD5 encryption algorithm can be used to calculate the MD5 checksum of the ` / a / b` file path in the configuration file backup directory. By comparing the two MD5 checksums, it can be determined whether the configuration file under the ` / a / b` file path has changed.

[0047] It is understood that the file backup method provided in this application embodiment obtains the path information of the configuration file to be migrated and generates an automated backup script based on the path information. When performing file backup, the backup script automatically backs up the configuration file to the shared directory of the network device. This not only reduces the dependence on external components, but also ensures that the shared directory is located within the network device and is independent of the network device's installation package. It will not be reset due to updates to the installation package on the network device, thus reducing the risk of configuration data loss.

[0048] In this embodiment of the application, after completing the above-mentioned configuration file backup, it is also necessary to restore the configuration file to its original path.

[0049] Based on this, embodiments of this application also provide a file recovery method, such as... Figure 2 As shown, the method may include: S201. Obtain the path information of the configuration file to be migrated corresponding to the network device, and generate a recovery script based on the path information.

[0050] In this embodiment of the application, the file recovery process is implemented based on the above-described file backup process.

[0051] In this embodiment of the application, the path information of the configuration file to be migrated corresponding to the white-box switch can be obtained by referring to the implementation process of the aforementioned file backup stage, which will not be repeated here.

[0052] In this embodiment, after parsing the recorded file paths from the file path set P, a recovery script is generated based on the obtained path information of the configuration file to be migrated. Specifically, this can be implemented using an automatic recovery script generation function, which can be denoted as: The automatic recovery script generation function automatically generates a recovery script based on file paths in the file path set P. Specifically, the file paths parsed from the file path set P are used as input parameters to the automatic recovery script generation function, which then outputs the recovery script. The generated recovery script is placed in migration-post-hooks.d and can be named restore.sh. Calling restore.sh will revert the configuration file back to its original path.

[0053] The recovery script can be understood as program code that automatically recovers configuration files, data, etc.

[0054] S202. Based on the recovery script, restore the configuration file backed up to the shared directory of the record configuration file set on the network device to the path information corresponding to the configuration file.

[0055] In this embodiment of the application, the shared directory for recording configuration files is the " / host" directory of the white-box switch SONiC.

[0056] In this embodiment, a recovery script is used to restore the backup configuration file in the / host directory to its original file path. For example, if the configuration file was originally stored in the / a / b path and was later stored in the / host / a / b path after backup, the recovery stage involves migrating the configuration file in the / host / a / b path to the original / a / b path.

[0057] In this embodiment of the application, the configuration file backed up to the shared directory is restored to the file path corresponding to the configuration file based on the recovery script. This can be achieved in the following way: during the process of the network device's system update being completed and the updated system being started, the recovery script is called and executed; based on the recovery function in the recovery script, the configuration file backed up to the shared directory on the network device that records the configuration file is restored to the path information corresponding to the configuration file.

[0058] In this embodiment of the application, the specific recovery process utilizes the aforementioned automatic recovery script generation function. Based on this, if the white-box switch completes its system update and calls `config-setup boot` during system startup, it triggers the execution of the generated `restore.sh` from `migration-post-hooks.d`. `backup.sh` is responsible for restoring the configuration files backed up to ` / host / backup` to their original paths. This recovery process can be represented by formula (5): (5) Formula (5) means that the configuration files in each file path under / host / backup are migrated to each file path in the original file path set P.

[0059] In this embodiment, the recovery function described above can be represented by the following formula (6): (6) Formula (6) means restoring the configuration file corresponding to the i-th file path to be migrated in / host / backup to its original i-th file path. For example, restoring the configuration file under the / host / backup / a path to its original / a path.

[0060] It should be noted that for each file path in the file path set P The recovery operation is equivalent to... Copy the configuration file from the path back to the original path. .

[0061] In this embodiment, before restoring the backed-up configuration file, it is necessary to ensure that the configuration file has not been tampered with. Therefore, in this embodiment, based on the recovery script, before restoring the configuration file in the shared directory of the record configuration file set on the network device to the path information corresponding to the configuration file, first encrypted information is obtained. The first encrypted information is generated after encrypting the configuration file under the path information based on a preset encryption algorithm during the backup process. The preset encryption algorithm is used to encrypt the configuration file to be restored corresponding to each path information in the shared directory to obtain the second encrypted information of the configuration file to be restored. Based on the first encrypted information and the second encrypted information, it is determined whether the configuration file to be restored has been tampered with, so that if the configuration file to be restored has not been tampered with, the configuration file in the shared directory of the record configuration file set on the network device is restored to the path information corresponding to the configuration file.

[0062] In this embodiment of the application, during the recovery phase, the system can obtain the MD5 checksum value corresponding to each file path from the / host / backup / checksum.md5 file.

[0063] It should be noted that the method for generating the MD5 checksum value for each file path in the / host / backup / checksum.md5 file can refer to the aforementioned embodiment, and will not be repeated here.

[0064] In this embodiment of the application, before restoring the configuration information corresponding to each file, the same MD5 encryption algorithm as in the backup stage can be used to encrypt the configuration file corresponding to each file path in the / host / backup directory to obtain the MD5 checksum (i.e., the second encryption information) corresponding to each file path in the / host / backup directory.

[0065] In this embodiment, the system verifies the MD5 checksum corresponding to each file path calculated during the recovery phase based on the MD5 checksum recorded in the / host / backup / checksum.md5 file to ensure the integrity of the backed-up configuration file. Specifically, this can be implemented using an MD5 verification function, which can be denoted as: . This is used to compare whether the MD5 checksum of the backed-up configuration file is the same as that of the configuration file to be restored.

[0066] Among them, the MD5 verification function The definition is shown in the following formula (7): (7) in, This represents the first encrypted information calculated during the backup phase. This represents the second encrypted information calculated during the recovery phase.

[0067] In this embodiment, if the MD5 checksum of all configuration files is True, the migrated configuration files are considered to be consistent, and a recovery operation is performed. Otherwise, an error log is generated and a data inconsistency is indicated.

[0068] It is understood that the file recovery method provided in this application embodiment obtains the path information of the configuration file to be migrated and generates an automated recovery script based on the path information. When the configuration file is recovered, the recovery script automatically restores the configuration file backed up to the shared directory to the path information corresponding to the configuration file. This not only reduces the dependence on external components, but also ensures that the shared directory is in the network device and is independent of the network device's installation package. The configuration file to be recovered will not be reset due to updating the installation package on the network device. Thus, the risk of configuration data loss can be reduced.

[0069] Based on the above embodiments, if we analyze the algorithm complexity of automatically generating scripts: the algorithm for automatically generating backup and recovery scripts mainly relies on parsing and traversing the file path set P. For each path in the file path set P... The time complexity of generating backup and recovery scripts is O(n). , where n is the number of elements in the file path set P.

[0070] The algorithm complexity is calculated as follows: The time complexity of generating the backup script is shown in the following formula (8): (8) The time complexity of generating the recovery script is shown in the following formula (9): (9) The time complexity of backing up and restoring the entire system is shown in the following formula (10): (10) Where n is the number of file paths of the configuration files to be migrated recorded in config_db.json.

[0071] As can be seen, the algorithm complexity for file backup and recovery in this embodiment is O(n). This indicates that the file backup and recovery process grows linearly with the number of files (n) being migrated. Compared to traditional item-by-item migration and manual backup methods, linear time complexity means that it can still maintain a fast response when migrating a large number of configuration files. For white-box switches, the low-complexity design significantly reduces the latency of upgrade operations and avoids service interruptions caused by excessive system downtime.

[0072] Based on the above embodiments, this application, during the upgrade and complete replacement of the SONiC operating system of a white-box switch, designs a linkage mechanism between pre-migration and subsequent migration based on the dual-system shared / host directory mechanism. By executing custom scripts at different stages, critical data, including user information, is backed up and restored, ensuring that data is not lost due to system reinstallation or version change. Compared with related technologies, it has the following technical advantages: Related technologies use a File Control Center (BMC) for file saving and recovery. When the BMC fails, the file saving and recovery functions fail, resulting in high coupling. However, the embodiments of this application can achieve file saving and recovery of the switch without relying on a BMC, enabling a scenario where no external components are needed.

[0073] In related technologies, files to be protected are recorded in a database, and separate partitions are created for backup of the files to be saved. However, when the operating system is changed, neither the partitions nor the saved files can be preserved. In the scenario of upgrading or changing the operating system, the embodiments of this application can save and restore critical configuration files because the / host directory remains unchanged, and no additional partitions are needed to occupy system space.

[0074] It can reduce operation and maintenance costs and human resource requirements: The embodiments of this application significantly reduce the need for manual configuration backup and recovery operations through automated script generation and execution mechanisms, allowing network administrators to focus on core network optimization work, reducing manual intervention and maintenance time, thereby reducing overall operation and maintenance costs.

[0075] Enabling flexible deployment and easily scalable network environments for white-box switches: The embodiments of this application are particularly suitable for the white-box switch ecosystem, supporting seamless switching and configuration migration of network devices between different systems and versions, enhancing the scalability and flexibility of the network system. Cloud computing, data center, and enterprise network customers can quickly respond to changes in business needs and adapt to network topology and system version updates at a lower cost.

[0076] Based on the above embodiments, this application also provides a schematic diagram of the overall process of file backup and recovery, such as... Figure 3 As shown, the specific implementation process is as follows: The SONiC operating system of the white-box switch records the file paths of key configuration files in config_db.json. Based on the file paths in config_db.json, it generates backup and recovery scripts. These scripts enable the automatic migration of key configuration files and other configurations (i.e., all configuration files and data that need to be backed up and restored). The automated migration includes the following core processes: recording backup file paths, automatic script generation, and file migration after system switchover.

[0077] The specific process design is as follows: White-box switches need to save the file path of the configuration file, which is recorded in / etc / sonic / config_db.json.

[0078] The MD5 encryption algorithm is used to generate MD5 checksums for configuration files under each file path, and the results are stored in the file / host / backup / checksum.md5.

[0079] It should be noted that the added MD5 checksum mechanism generates and verifies MD5 checksums during configuration file backup and recovery to ensure that migration files have not been altered or corrupted during transmission and storage. This mechanism enhances data consistency and integrity, preventing data loss or file tampering.

[0080] During the backup phase, when the white-box switch upgrades the system installation package, the sonic_installer install operation triggers the system to generate backup scripts and migration scripts corresponding to the configuration information stored in the file path in config_db.json. The backup scripts are placed in migration-pre-hooks.d and migration-post-hooks.d. At the same time, the backup scripts under migration-pre-hooks.d are executed to back up the configuration files to the / host / backup path.

[0081] It should be noted that backup scripts and recovery scripts can be generated simultaneously.

[0082] It should be noted that, in this embodiment of the application, the backup script is automatically generated in migration-pre-hooks.d and the recovery script is recorded in migration-post-hooks.d by the file path recorded in config_db.json. This automated process eliminates the complexity of manual configuration and ensures that critical system data can be automatically saved and restored after system upgrade and reinstallation.

[0083] It should be noted that the backup path can be / host / backup or / host / old_config. The specific name can be selected according to the actual situation, and no specific limitation is made in this embodiment.

[0084] Since the / host directory of the SONiC white-box switch is shared by multiple systems, upgrading a single system will not change the / host directory. Therefore, the system starts the config-setup boot service after booting.

[0085] During the recovery phase, before migrating back to the original path, the system can also obtain the MD5 checksum value for each file path from the ` / host / backup / checksum.md5` file and calculate the MD5 checksum value for each file path backed up in the ` / host` directory. By comparing the two MD5 checksum values, the system verifies the data consistency of the migrated configuration files.

[0086] If the configuration files are consistent, execute the recovery script under migration-post-hooks.d to migrate the critical configuration files back to their original paths.

[0087] Based on the above embodiments, another embodiment of this application provides a file backup device 1, such as... Figure 4 As shown, the file backup device 1 includes: The first determining unit 10 is used to obtain the path information of the configuration file to be migrated corresponding to the network device, and generate a backup script based on the path information.

[0088] Backup unit 11 is used to back up the configuration files under the path information to the shared directory of the record configuration files set on the network device, based on the backup script.

[0089] In one embodiment, the file backup device 1 may further include a recall unit.

[0090] The calling unit is used to invoke and execute backup scripts when updating the system of network devices.

[0091] Backup unit 11 is also used to back up the configuration file under the path information to the shared directory of the record configuration file set on the network device based on the backup function in the backup script.

[0092] In one embodiment, the file backup device 1 may further include a recording unit.

[0093] The recording unit is used to pre-record the path information corresponding to all configuration files to be migrated in the network device in the file path set.

[0094] The first determining unit 10 is also used to parse the set of file paths to obtain path information when updating the system of the network device.

[0095] In one embodiment, the file backup device 1 may further include an encryption unit.

[0096] The encryption unit is used to encrypt the configuration file under each path information in the file path set using a preset encryption algorithm to obtain the first encrypted information corresponding to the configuration file under each path information, so as to verify whether the configuration file has been tampered with based on the first encrypted information during the process of restoring the configuration file under each path information.

[0097] This application provides a file backup device that obtains the path information of the configuration file to be migrated corresponding to the network device, and generates a backup script based on the path information. Based on the backup script, the configuration file under the path information is backed up to a shared directory set on the network device for recording configuration files. Thus, the file backup device proposed in this application obtains the path information of the configuration file to be migrated and generates an automated backup script based on the path information. When performing file backup, the backup script automatically backs up the configuration file to the shared directory of the network device. This not only reduces the dependence on external components, but also ensures that the shared directory is located within the network device and is independent of the network device's installation package, so it will not be reset due to updates to the installation package on the network device. In this way, the risk of configuration data loss can be reduced.

[0098] Based on the above embodiments, another embodiment of this application provides a file recovery device 2, such as... Figure 5 As shown, the file recovery device 2 includes: The second determining unit 20 is used to obtain the path information of the configuration file to be migrated corresponding to the network device, and generate a recovery script based on the path information.

[0099] Recovery unit 21 is used to restore the configuration file in the shared directory of the record configuration file set on the network device, which is backed up, to the path information corresponding to the configuration file, based on the recovery script.

[0100] In one embodiment, the file recovery device 2 may further include a recall unit.

[0101] The calling unit is used to call and execute the recovery script during the process of completing the system update of the network device and starting the updated system.

[0102] Recovery unit 21 is also used to restore the configuration file in the shared directory of the record configuration file set on the network device, which is backed up, to the path information corresponding to the configuration file, based on the recovery function in the recovery script.

[0103] In one embodiment, the file recovery device 2 may further include: an acquisition unit and an encryption unit.

[0104] The acquisition unit is used to acquire first encrypted information, wherein the first encrypted information is generated after the configuration file under the path information is encrypted based on a preset encryption algorithm during the backup process of the configuration file under the path information.

[0105] The encryption unit is used to encrypt the configuration file to be recovered corresponding to each path information in the shared directory using a preset encryption algorithm, so as to obtain the second encrypted information of the configuration file to be recovered.

[0106] The second determining unit 20 is further configured to determine, based on the first encrypted information and the second encrypted information, whether the configuration file to be restored has been tampered with, so that if the configuration file to be restored has not been tampered with, the configuration file backed up to the shared directory of the record configuration file set on the network device is restored to the path information corresponding to the configuration file.

[0107] This application provides a file recovery device that obtains the path information of the configuration file to be migrated corresponding to a network device, and generates a recovery script based on the path information. Based on the recovery script, the configuration file backed up to the shared directory of the configuration file on the network device is restored to the path information corresponding to the configuration file. Thus, by obtaining the path information of the configuration file to be migrated and generating an automated recovery script based on the path information, the configuration file backed up to the shared directory is automatically restored to the path information corresponding to the configuration file when the configuration file recovery is performed. This not only reduces the dependence on external components, but also, since the shared directory is in the network device and independent of the network device's installation package, the configuration file to be recovered will not be reset due to updating the installation package on the network device. In this way, the risk of configuration data loss can be reduced.

[0108] Figure 6 This is a schematic diagram of the composition structure of an electronic device 3 provided in an embodiment of this application. In practical applications, based on the same disclosed concept of the above embodiments, such as... Figure 6 As shown, the electronic device 3 in this embodiment of the application includes a processor 30, a memory 31, and a communication bus 32.

[0109] In specific embodiments, the first determining unit 10, backup unit 11, calling unit, recording unit, encryption unit, second determining unit 20, recovery unit 21, and acquisition unit described above can be implemented by a processor 30 located on the electronic device 3. The processor 30 can be at least one of the following: Application Specific Integrated Circuit (ASIC), Digital Signal Processor (DSP), Digital Signal Processing Device (DSPD), Programmable Logic Device (PLD), Field Programmable Gate Array (FPGA), CPU, controller, microcontroller, and microprocessor. It is understood that for different devices, the electronic device used to implement the above processor functions can also be other types; this application does not impose specific limitations.

[0110] In this embodiment, the electronic device 3 includes a file backup device and a file recovery device. When the electronic device 3 includes a file backup device, the communication bus 32 is used to establish communication between the processor 30 and the memory 31. When the processor 30 executes the running program stored in the memory 31, it implements the following file backup method: Obtain the path information of the configuration file to be migrated corresponding to the network device, and generate a backup script based on the path information; based on the backup script, back up the configuration file under the path information to the shared directory for recording configuration files set on the network device.

[0111] In one embodiment, the processor 30 is further configured to call and execute a backup script when updating the network device's system; based on the backup function in the backup script, back up the configuration file under the path information to the shared directory of the record configuration file set on the network device.

[0112] In one embodiment, the processor 30 is further configured to pre-record path information corresponding to all configuration files to be migrated in the network device in the file path set; and to parse the file path set to obtain path information when updating the system of the network device.

[0113] In one embodiment, the processor 30 is further configured to encrypt the configuration file under each path information in the file path set using a preset encryption algorithm to obtain the first encrypted information corresponding to the configuration file under each path information, so as to verify whether the configuration file has been tampered with based on the first encrypted information during the process of restoring the configuration file under each path information.

[0114] In this embodiment, when the electronic device 3 includes a file recovery device, the communication bus 32 is used to realize the connection communication between the processor 30 and the memory 31; when the processor 30 executes the running program stored in the memory 31, it implements the following file recovery method: Obtain the path information of the configuration file to be migrated corresponding to the network device, and generate a recovery script based on the path information; based on the recovery script, restore the configuration file backed up to the shared directory of the configuration file set on the network device to the path information corresponding to the configuration file.

[0115] In one embodiment, the processor 30 is further configured to call and execute a recovery script during the process of completing a system update of the network device and starting the updated system; based on the recovery function in the recovery script, restore the configuration file backed up to the shared directory of the record configuration file set on the network device to the path information corresponding to the configuration file.

[0116] In one embodiment, the processor 30 is further configured to obtain first encrypted information, wherein the first encrypted information is generated by encrypting the configuration files under the path information based on a preset encryption algorithm during the backup process of the configuration files under the path information; using the preset encryption algorithm, the configuration files to be restored corresponding to each path information in the shared directory are encrypted to obtain second encrypted information of the configuration files to be restored; based on the first encrypted information and the second encrypted information, it is determined whether the configuration files to be restored have been tampered with, so that if the configuration files to be restored have not been tampered with, the configuration files in the shared directory for recording configuration files set on the network device are restored to the path information corresponding to the configuration files.

[0117] Based on the above embodiments, this application provides a storage medium storing a computer program thereon. The computer-readable storage medium stores one or more programs, which can be executed by one or more processors and applied in a file backup device / file recovery device. The computer program implements the file backup and recovery methods described above.

[0118] Based on the above embodiments, this application provides a computer program product, including a computer program that can be executed by one or more processors and applied in a file backup device / file recovery device. The computer program implements the file backup and recovery methods described above.

[0119] It should be noted that, in the embodiments of this application, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0120] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solutions of the embodiments of this application, or the parts that contribute to the related technology, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause an image display device (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of the embodiments of this application.

[0121] The above description is merely a specific implementation of the embodiments of this application, but the protection scope of this application is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this application should be included within the protection scope of this application.

Claims

1. A file backup method, characterized in that, The method includes: Obtain the path information of the configuration file to be migrated corresponding to the network device, and generate a backup script based on the path information; Based on the backup script, the configuration files under the path information are backed up to the shared directory for recording configuration files set on the network device.

2. The method according to claim 1, characterized in that, The step of backing up the configuration file under the path information to the shared directory for recording configuration files set on the network device, based on the backup script, includes: In the case of updating the system of the network device, the backup script is invoked and executed; Based on the backup function in the backup script, the configuration file under the path information is backed up to the shared directory of the record configuration file set on the network device.

3. The method according to claim 1, characterized in that, The step of obtaining the path information of the configuration file to be migrated corresponding to the network device includes: The path information corresponding to all configuration files to be migrated in the network device is pre-recorded in the file path set; When updating the system of the network device, the set of file paths is parsed to obtain the path information.

4. The method according to claim 3, characterized in that, After pre-recording the path information corresponding to all configuration files to be migrated in the network device in the file path set, the method further includes: For the configuration file under each path information in the file path set, a preset encryption algorithm is used to encrypt it to obtain the first encrypted information corresponding to the configuration file under each path information. In the process of restoring the configuration file under each path information, the configuration file is verified as tampered with based on the first encrypted information.

5. A file recovery method, characterized in that, The method includes: Obtain the path information of the configuration file to be migrated corresponding to the network device, and generate a recovery script based on the path information; Based on the recovery script, the configuration file backed up to the shared directory of the record configuration file set on the network device is restored to the path information corresponding to the configuration file.

6. The method according to claim 5, characterized in that, The step of restoring the configuration file backed up to the shared directory of the record configuration file set on the network device, based on the recovery script, to the path information corresponding to the configuration file includes: During the process of completing the system update of the network device and starting the updated system, the recovery script is invoked and executed; Based on the recovery function in the recovery script, the configuration file backed up to the shared directory of the record configuration file set on the network device is restored to the path information corresponding to the configuration file.

7. The method according to claim 5, characterized in that, Before restoring the configuration file backed up to the shared directory of the record configuration file set on the network device to the path information corresponding to the configuration file based on the recovery script, the method further includes: Obtain first encrypted information, wherein the first encrypted information is generated by encrypting the configuration file under the path information based on a preset encryption algorithm during the backup process of the configuration file under the path information; The preset encryption algorithm is used to encrypt the configuration file to be recovered corresponding to each path information in the shared directory, so as to obtain the second encrypted information of the configuration file to be recovered; Based on the first encryption information and the second encryption information, it is determined whether the configuration file to be restored has been tampered with. If the configuration file to be restored has not been tampered with, the configuration file backed up to the shared directory of the record configuration file set on the network device is restored to the path information corresponding to the configuration file.

8. An electronic device, characterized in that, The electronic device includes a processor and a memory; the processor executes a running program stored in the memory to implement the method as described in any one of claims 1 to 4, or the processor executes a running program stored in the memory to implement the method as described in any one of claims 5 to 7.

9. A storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1 to 4, or when the computer program is executed by a processor, it implements the method as described in any one of claims 5 to 7.

10. A computer program product, comprising a computer program, characterized in that, The computer program, when executed by a processor, implements the method as described in any one of claims 1 to 4, or the computer program, when executed by a processor, implements the method as described in any one of claims 5 to 7.