Skip to main content

Configuration Backup Automation for Dell Enterprise SONiC Switches using Python

Serhat Kahraman Oct 1, 2026
Configuration Backup Automation for Dell Enterprise SONiC Switches using Python

Overview

Scheduled configuration backups of network devices are an essential part of a recovery plan from switch failure or loss of specific configurations. In large data center networks, this task is typically managed by a network orchestration, management, or monitoring solution. In smaller environments, network operators or administrators can manually perform the backups. Recently, I conducted a proof of concept (PoC) with a customer who prefers open-source solutions. The customer needed to complete this task without using a commercial orchestration solution or manual methods. Ansible was not an option, as they were using other open-source automation tools that lacked configuration backup features. This blog post describes how we addressed their request and developed a solution. 

The solution is a Python script that creates ssh sessions to multiple Dell SONiC switches, retrieves the running configuration from switches, and writes them to individual files for each switch on the server. The script has been tested on Ubuntu 20 with Python 3, connected to six switches, and is working as expected. What follows is a step-by-step guide to test this script using an Ubuntu server:

Step 1. Setting Up a Server for Automation
Download the Ubuntu operating system from Enterprise Open Source and Linux | Ubuntu.  

Install the operating system on a bare metal server or as a virtual machine on a hypervisor. For example, you can use Ubuntu Server version 20.04.6 running as a virtual machine on VMware Workstation Pro. See Installing Ubuntu on VMware Workstation [Easiest Guide] - LinuxSimply.

Ubuntu Server 20.04.6 LTS welcome screenUbuntu Server 20.04.6 LTS welcome screen

Step 2. Installing, Updating and Upgrading the Required Packages

Install, update, and upgrade the required packages by running the following commands (the server needs to be connected to the Internet):
sudo apt update
sudo apt upgrade
sudo apt install net-tools
sudo apt install python3-pip
sudo pip3 install paramiko

   Screenshot of a Linux terminal showing Ubuntu package management commands, including apt update, apt upgrade, and installation checks for net-tools and python3-pip. The output indicates that system packages are up to date, the requested packages are already installed, and a pip3 install paramiko command is about to be performed.

Step 3. Setting up IP addresses
Set an IP address on the Ubuntu server that is reachable from the switch IP addresses. Here is a sample command:
 ifconfig ens33 10.0.0.111 netmask 255.255.255.0 up

Note: If you want this static IP address to be persistent across reboots, you must edit the yaml file in the /etc/netplan folder.
For more information, see Netplan static IP on Ubuntu configuration - LinuxConfig.

creenshot of the Linux ifconfig command output displaying three network interfaces: ens33, ens34, and the loopback interface lo, along with their IP addresses, netmasks, and network statistics. The highlighted ens33 interface is configured with IP address 10.0.0.11, while ens34 is configured with 192.168.14.133, showing a system connected to multiple networks.Network configuration output of the server

For information about the switch management IP assignment process in this example, see Dell EMC Networking S-Series: Basic Switch Management Configuration - SONIC 4.0.

Step 4. Downloading and Running the Script
Download the config-backup.py script from GitHub - serhatka/sonic-scripts: various python scripts for SONIC NOS.

Change the IP addresses, username, and password values in the switches section to suit your environment.

Copilot said:  Screenshot of a Python script that uses the Paramiko library for SSH connections and defines a list of network switches with connection parameters.Editing script values

Make the script executable by running the following command: chmod +x  /config-backup.py

To run the script, use: ./config-backup.py

Screenshot of a Linux terminal showing commands used to prepare and perform a Python backup script.Final steps to run the script

Copilot said:  Screenshot of the /home/etem/backup/ directory showing configuration backup output files generated by a Python script. The directory contains multiple timestamped SSH output text files for different network devices, along with the executable config-backup.py script used to create the backups.

The files are saved in the same folder as the script.

Copilot said:  Screenshot of a text editor displaying the output of a SONiC network switch configuration file. The output shows the SONiC login banner and the results of the show running-configuration | no-more command

Step 5. Setting Up an Environment for Scheduled Automation

To run this script on a daily schedule, you can set up a scheduled task or cron job on your server. The method depends on your operating system. Here are the general steps for scheduling a daily task on Unix-based systems such as Linux:

  1. Make the script executable by running the following command: chmod +x config-backup.py
  2. Open your crontab for editing by running the following command: crontab -e 
  3. Add an entry to the crontab that specifies when and how often you want to run the script. To run the script daily at a specific time, you can use a crontab entry such as the one in the following example: 0 6  * * * /path/to/python3 /path/to/config-backup.py

    The 0 in the first position specifies the minute (0-59).
    The 6 in the second position specifies the hour (0-23).
    The * in the other positions specifies any day of the month and any month of the year.

  4. Replace /path/to/python3 with the actual path to your Python 3 interpreter.
  5. Replace /path/to/config-backup.py with the actual path to your script.
  6. Save your changes and exit the crontab editor. The script will now run daily at the specified time. 
  7. Ensure that the Python interpreter and script have the necessary permissions to run.

Note: The specifics of setting up scheduled tasks can vary depending on your operating system and its version. Additionally, you may need to set up proper logging and error handling to ensure that the script runs smoothly in a scheduled environment.

References