I wrote a script for automatic backup of the BDCOM P3310C-2AC EPON configuration.

Actually the script itself:

#!/bin/bash
# Backup BDCOM
(
sleep 5
echo "admin"
sleep 5
echo "password"
sleep 5
echo "enable"
sleep 2
echo "write all"
sleep 15
echo "copy startup-config tftp://bdcom.cfg 192.168.1.2"
sleep 2
echo "quit"
sleep 10
echo "quit"
) | telnet 192.168.1.3
mv /srv/tftp/bdcom.cfg /backups/devices/pon/`date +%Y-%m-%d`_bdcom.cfg

You can transfer more files:

echo "copy flash:ifindex-config tftp://`date +%Y-%m-%d`_1028_nas_10_ifindex.cfg 192.168.1.2"
sleep 2
echo "copy flash:config.db tftp://`date +%Y-%m-%d`_1028_nas_10_configdb.cfg 192.168.1.2"
sleep 7

For example, put the contents of the script into the backup_cfg.sh file and add it to the task scheduler by adding the following line to the /etc/crontab file:
0 1 * * * root /backups/scripts/backup_bdcom.sh >/dev/null 2>&1

The file can be opened, for example, in a nano text editor (Ctrl+X to exit, y/n to save or cancel changes):

sudo nano /etc/crontab

I will briefly describe his work, he connects via telnet to bdcom 192.168.1.3 and copies the configuration to the tftp server 192.168.1.2, then the file is moved to a convenient directory for storage.
The script was written for Linux operating systems, currently I use it in Ubuntu Server.
How to start a tftp server, see in my articles:
Installing and Configuring a TFTP Server in Ubuntu
Starting a TFTP server in Windows

In a similar way, you can back up using expect, for example

#!/usr/bin/expect
# sudo apt install expect
set timeout 30
#set host [lindex $argv 0]
#set user [lindex $argv 1]
#set password [lindex $argv 2]
#spawn telnet $host
spawn telnet 192.168.2.3
expect "Username:"
#send "$user\n"
send "admin\n"
expect "Password:"
#send "$password\n"
send "password\n"
expect "Switch>"
send "enable\n"
expect "Switch#"
send "copy startup-config tftp://ixnfo.cfg 192.168.2.2\n"
expect "Switch#"
send "quit\n"
expect "Switch>"
send "quit\n"

See also my article:
Using and configuring CRON

Did my article help you? How about buying me a cup of coffee as an encouragement? Buy me a coffe.

Leave a comment

Leave a Reply