Cisco Nexus 3064 Backup Script

I will give an example of a script for backing up the configuration of a Cisco Nexus 3064 and the like.

I decided to write a script using expect, let’s install it:

sudo apt install expect

Script content:

#!/usr/bin/expect
# sudo apt install expect
set timeout 30
spawn sshpass -p PASSWORD ssh admin@192.168.5.5
expect "*ixnfo#"
send "copy running-config tftp: vrf default\r"
expect "*running-config*"
send "cisco-nexus-3064\n"
expect "*Enter hostname for the tftp server:"
send "192.168.5.10\n"
expect "ixnfo#"
send "exit\n"
expect eof
system mv /srv/tftp/cisco-nexus-3064 /srv/tftp/cisco-nexus-3064_`date +%Y-%m-%d`.cfg

The script connects to the device via SSH and executes the command to copy the configuration to the TFTP server, as well as the last command, you can rename and move the configuration file to any convenient location.

In order for the script to be automatically executed, add it to the /etc/crontab file, for example, for daily execution at 1 am:

0 1 * * * root /backups/scripts/backup_cisco3064.sh >/dev/null 2>&1

See also my articles:
Installing and Configuring a TFTP Server in Ubuntu
Starting a TFTP server in Windows
Using and configuring CRON

Leave a comment

Leave a Reply