SonicLab18 lessons · Available
On this page
Configuration & management · 3 of 03

Persistence, Changes, and Recovery

Plan a bounded change, retain the before state, and separate recovery from saving the final intended configuration.

Prerequisite: Inspecting Interfaces and RoutesLesson 06 · operator workflow
By the end, you should be able to:
  • Protect both saved startup and running configuration before a change.
  • Describe a reversible lab change with explicit checks and an inverse.
  • Explain the effects and limits of save, load, and reload.
Baseline: community SONiC 202505 release-branch source, pinned in the references; single ASIC, default namespace, community CLI. This is not a claim about the latest release or a certified vendor image. The Windows checkout was cross-checked separately. Commands are examples only; no device changes or live verification were performed.

Define the change and the way back

The example below is a paper exercise for an isolated lab port. It assumes Ethernet0 is verified unused, initially administratively up, outside management access and forwarding dependencies, and reserved for this exercise. On a real target, choose a verified spare port and check its VLAN, LAG, routing, ACL, mirroring, and other dependencies first.

Have console or independent management access, a maintenance window if service can be affected, and an owner for recovery. Record both intended and observed before state. Do not use a reboot as a shortcut to undo a small change: unsaved work elsewhere may be lost.

A bounded change with a decision point
A bounded change with a decision pointCapture before state, change a single lab port, verify intended and observed effects, then either restore using the inverse or retain an approved final state. Persistence is a separate decision after validation.CaptureRunning + startupChangeOne lab portVerifyIntent + observationsDecideRestore or retainSave only the approved final running configuration; recovery is not automatic.
Original workflow. These are decision stages, not an automated transaction or a promise of confirmed rollback.

1. Preserve startup and running state separately

For the single-ASIC baseline, use a new root-only backup directory. Stop if the chosen directory already exists; choose a fresh name rather than overwrite an earlier recovery point. Configuration exports can contain credentials.

sudo mkdir -m 700 /var/backups/sonic-review
sudo cp -p /etc/sonic/config_db.json /var/backups/sonic-review/startup-before.json
sudo config save /var/backups/sonic-review/running-before.json

Controlled backup examples: create files on a lab device only after planning. Retain and review the overwrite confirmation; no automatic yes flag is used. Illustrative only; not executed on a SONiC device.

The copy preserves the existing startup file. The named config save exports current CONFIG_DB to a separate file; it does not replace the default startup file. Freeze concurrent changes while recording the baseline. This is a configuration snapshot, not a backup of the OS, vendor files, or every daemon’s independent state.

sudo python3 -m json.tool /var/backups/sonic-review/running-before.json > /dev/null

Read-only syntax check of the exported file. Illustrative only; not executed on a SONiC device.

A successful JSON parse checks syntax, not YANG validity, hardware compatibility, or recoverability. Match the image’s validation and restore procedure. Multi-ASIC systems need the supported per-instance or combined-file workflow, not this single-ASIC assumption.

Read further: 202505 configuration CLI implementation · 202505 configuration CLI tests.

2. Apply one change and use its inverse

show runningconfiguration ports Ethernet0
show interfaces status Ethernet0
sudo config interface shutdown Ethernet0
show runningconfiguration ports Ethernet0
show interfaces status Ethernet0

Controlled lab-only sequence. This would disable the chosen port; it is not executed by this page. Illustrative only; not executed on a SONiC device.

Expect administrative intent to become down and inspect whether the operational view follows. The initial operational state may already have been down on an unconnected spare port; that is why the before record matters. Unexpected impact is a reason to stop and restore.

sudo config interface startup Ethernet0
show runningconfiguration ports Ethernet0
show interfaces status Ethernet0

Explicit inverse for this example’s initial administrative-up baseline. Illustrative only; not executed on a SONiC device.

Verify restored administrative intent and compare observed state with the before record. “Startup” here brings an interface administratively up; it does not mean “save startup configuration.” If the original state was down, this inverse would be wrong. Recheck dependencies and relevant traffic evidence before closing the change.

Read further: 202505 configuration CLI implementation · 202505 interface inspection implementation.

3. Save only an accepted final state

sudo config save

Persistence action, shown separately. It overwrites the default startup configuration after confirmation. Illustrative only; not executed on a SONiC device.

This saves current CONFIG_DB, including unrelated unsaved changes; it is not a selective commit of one port. For the exercise, restore the initial state and leave the existing startup file alone unless an approved final change should persist. After an approved save, inspect the saved fields as well as running intent and operational evidence.

ActionBaseline behavior
config save [filename]Exports current CONFIG_DB to the chosen file; default is the startup file.
config load [filename]Writes input configuration into the DB without the clear-and-restart workflow. It is not a guaranteed full replacement or deletion of absent keys.
config reload [filename]Clears and reloads configuration with service restart behavior by default. It can disrupt forwarding and management access.

Read further: 202505 configuration CLI implementation · 202505 command reference (pinned).

If targeted recovery is not enough

Prefer the verified inverse for this bounded port exercise. A bulk restore is a separate maintenance operation requiring a valid, compatible baseline, console access, impact approval, and a plan to verify services, interfaces, routes, and reachability afterward.

config reload --help
# Separate maintenance recovery example; not part of the port exercise:
sudo config reload /var/backups/sonic-review/running-before.json

The first command is help only. The second is disruptive recovery, not a dry run. Illustrative only; not executed on a SONiC device.

Do not bypass confirmation, readiness checks, or service handling with force flags in a teaching recovery. A successful reload is not proof that every dependent service or packet path recovered. It also does not automatically make the chosen snapshot the default startup file. Reconcile persistence only after validation and approval.

Read further: 202505 configuration CLI implementation · 202505 command reference (pinned).

Key takeaways

  • Preserve the startup file and export running CONFIG_DB as distinct before states.
  • Use an inverse that matches the recorded original state and scope.
  • config save persists all current CONFIG_DB, not just the latest command.
  • load and reload differ; reload can interrupt traffic and access.
  • JSON syntax and command success are not end-to-end recovery proof.

Check your understanding

Six questions, four choices each. Check each answer, review the explanation and score, and retry.

Sources & baseline

Reviewed 18 October 2026. Community 202505 branch snapshots: sonic-utilities 7511bf2f8ea3; sonic-buildimage ff3c0c9f686a. Confirm commands with local help and image support before using them. Historical prose within a release branch can describe older behavior; implementation was checked for the examples used here.

Additional read-only Windows source cross-check: sonic-buildimage 128f6802b6e1, sonic-utilities cc4fbb3e8313 (config/main.py, show/main.py, and show/interfaces/__init__.py). This different checkout supports the roles illustrated; it is not presented as a 202505 binary. Full paths, revisions, and verification limits are recorded in SOURCE-REVIEW.txt beside this page.

Lesson 06 · Knowledge check