华为交换机恢复出厂设置:三种方法的区别与验证 - 夜莺博客

华为交换机恢复出厂设置:三种方法的区别与验证

华为 S 系列交换机所谓“恢复出厂设置”其实是三件不同的事:按 PNP 按钮、执行一键恢复、以及只清空配置文件。三者删掉的东西差别很大,选错了轻则丢配置、重则连管理 IP 和启动文件一起清掉,只能靠 Console 重来。本文按华为官方《S 系列交换机故障处理》文档,把三种方法的命令、删除范围、适用场景和验证步骤一次讲清楚,并给出执行前的备份清单。

先分清三个概念

  • 出厂配置(factory settings):设备出厂自带的基础配置,保存在受保护目录的 $_default.cfg 文件中;当没有配置文件或配置文件损坏时,设备靠它正常启动运行。
  • 配置文件(configuration file):设备上电时从默认存储目录读取、用于初始化系统的文件,用 display startup 可查看本次与下次启动使用的配置文件,用 display saved-configuration 查看下次启动配置文件。
  • 当前配置(current configuration):设备运行期间生效的配置,用 display current-configuration 查看;只有执行 save 后才会写入默认存储介质,成为下次启动配置。

方法一:按 PNP 按钮(无需登录)

带有 PNP 按钮的设备,长按该按钮 6 秒以上即可恢复出厂设置并自动重启。这种方法不需要登录交换机,适合设备已经在现场、忘记密码或无法登录的场景;代价是它会删除除下次启动的系统软件包、补丁文件、插件和 License 文件以外的全部目录和文件。

方法二:一键恢复 reset factory-configuration

<HUAWEI> reset factory-configuration
Warning: The command will delete all the configurations and files (except the startup,
patch, module, and license files) from the device. Continue? [Y/N]:y
Warning: The system will reboot after configurations and files are deleted. Continue? [Y/N]:y

执行后设备自动重启,效果与按 PNP 按钮接近:配置文件、数据文件和自定义目录都会被清理,系统软件包等保留。适合设备转用途、需要彻底回到“新机”状态的场合。

方法三:只清空配置文件 reset saved-configuration

<HUAWEI> reset saved-configuration
Warning: The action will delete the saved configuration in the device.
The configuration will be erased to reconfigure. Continue? [Y/N]:y
Info: Succeeded in clearing the configuration in the device.

<HUAWEI> reboot
Info: The system is now comparing the configuration, please wait...
Warning: The configuration has been modified, and it will be saved to the next
startup saved-configuration file flash:/vrpcfg.zip. Continue? [Y/N]:n
System will reboot! Continue?[Y/N]:y

这里有两个交互必须答对:reset saved-configuration 后的确认要输入 yreboot 时“是否保存配置”必须回答 n——如果选了 y,设备会把当前配置重新写成下次启动文件,等于白清。这个方法只清除交换机当前的配置和配置文件,其他文件(日志、License、补丁)都保留。

执行前的备份清单

<HUAWEI> display current-configuration
<HUAWEI> display startup
<HUAWEI> display saved-configuration
<HUAWEI> save                                     ! 备份到本地
<HUAWEI> tftp 192.168.1.100 put vrpcfg.zip backup-vrpcfg.zip

至少要保存当前配置、下次启动文件名、管理 IP/VLAN、堆叠(iStack/CSS)参数和链路聚合配置,否则恢复后需要重新规划。

三种方法对比

方法 是否需要登录 删除范围 典型场景
长按 PNP 按钮 除系统软件包/补丁/插件/License 外的全部文件 现场无账号、密码丢失
reset factory-configuration 同上,执行后自动重启 设备转用途、彻底恢复出厂
reset saved-configuration 仅当前配置与配置文件 清空配置保留系统文件,重配设备

相关阅读:华为交换机恢复出厂设置方法汇总reset saved-configuration 与 reset factory-configuration 的区别 以及 华为 CE 交换机 display 排障命令

原文链接:华为技术支持:S 系列交换机恢复出厂配置(V200)