Backup Dell SonicWALL configurations via CLI

At one of my my previous work places we utilize multiple Dell SonicWALL network devices. I’ve written an Expect plus a BASH script (yes, two scripts) that can be cron job to auto backup configurations. We needed the Expect script to interact with SonicWall SSH session.

By looking at the BASH script you Just need to add/substract the proper associative array depending on how many devices you are backing up from.

SonicWALL exports configuration via FTP so you do need a FTP server setup. I have a ftpuser account setup with password of “ftpuser” and a folder called “network_configurations” under that user’s root directory. Both Expect and BASH scripts sits in /home/ftpuser/bin/scripts/. The server running this job and hosting the FTP server is 192.168.1.100.

So if I want to add new SonicWALL device to the backup list, I’d just add something like following.

FWdevice[192.168.1.4]="admin PASSWORD"

 

Expect script content:

#!/usr/bin/env expect

set server [lindex $argv 0];
set username [lindex $argv 1];
set userpw [lindex $argv 2];
set devicename [lindex $argv 3];

set timeout 60

spawn ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no $username@$server

expect -re ".*?assword:"
send "$userpw\n"

expect -re ">"
send "export current-config cli ftp ftp://ftpuser:ftpuser@192.168.1.100/network_configurations/$devicename.txt\n"

expect -re ">"
send "exit\n"

 

Bash script content:

#!/usr/bin/env bash

declare -A FWdevice

FWdevice[10.1.1.1]="admin PASSWORD"
FWdevice[10.1.1.2]="admin PASSWORD"
FWdevice[10.1.1.3]="admin PASSWORD"
FWdevice[192.168.1.1]="admin PASSWORD"

for v in ${!FWdevice[*]}
do
    echo "Working on saving configuration on network device $v..."
    /home/ftpuser/bin/scripts/sonicwallbackup.exp $v ${FWdevice[$v]} $v
done

exit 0

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.