Introduction: How to Backup a Foundry Networks Device

About: I like to tinker with just about anything, sometimes it works out in the end. Have fun looking at the projects, try tearing something open and let me know how it goes. cheers, -Joe
This instructable will show a script that can be used to automate backups of a foundry networks switch/router/firewall.

Step 1: Requirements

This script uses expect to automate the backups and runs on a linux system.

If you have never check out expect, Oreilly has a great book "Exploring Expect"
http://oreilly.com/catalog/9781565920903/

Step 2: Variables

Set up some variables. You will need to change the username, password, foundry and prompt variables.

#!/usr/bin/expect
#Expect script to backup config of foundry devices
#Joe McManus

#Set some vars
set timeout 60
set user "telnet"
set password "password"
set foundry "foundry.foo.bar.com"
set basedir "/mnt/netapp/backups/foundry.foo.bar.com"
set log "[timestamp -format %Y-%m-%d]-config.txt"
set mailto "joe@foo.com"
set mailsubject "Error: foundry backup failed [timestamp -format %Y-%m-%d] "
set mailfail ""
set prompt "telnet@FLS648"

Step 3: Connect

This part of the script attempts to connect to the foundry.
send_user "Foundry Backup Script\n"

send_user "Connecting to $foundry\n"

spawn telnet $foundry
expect {
"Password:" {
send "$password\r"
expect {
"$prompt" {
send_user "Connected"
} "failure" {
send_user "Invalid password, exiting"
set mailfail "Invalid password, exiting"
close
} timeout {
send_user "No prompt returned"
set mailfail "No prompt returned"
close
}
}
} "No route to host" {
send_user "Unable to connect to $foundry\n"
set mailfail "Unable to connect to $foundry\n"
} "Name or service not known" {
send_user "Unable to connect to $foundry\n"
set mailfail "Unable to connect to $foundry\n"
} timeout{
send_user "Timeout conncting to $foundry"
set mailfail "Timeout conncting to $foundry"
close
}
}

if { $mailfail != "" } {
exec /bin/mail -s$mailsubject $mailto << "
$mailfail"
exit
}

Step 4: Disable Paging.

Disable the "more" prompt so we can download the config.

send "enable\r"
expect {
"$prompt Switch#" {
send_user "Enabled"
} default {
send_user "Enable failed"
set mailfail "ScreenOS did not except paging option."
close
}
}

if { $mailfail != "" } {
exec /bin/mail -s$mailsubject $mailto << "
$mailfail"
exit
}

send "skip-page-display\r"
expect {
"Disable page display mode*$prompt" {
send_user "\nPaging Disabled\n"
} default {
send "ScreenOS did not except paging option.\n"
set mailfail "ScreenOS did not except paging option."
close
}
timeout {
send_user "ScreenOS did not except paging option\n"
set mailfail "ScreenOS did not except paging option."
close
}
}
if { $mailfail != "" } {
exec /bin/mail -s$mailsubject $mailto << "
$mailfail"
exit
}

Step 5: Get Config

This part of the script gets the configuration.

send_user "Downloading Configuration\n"
log_file $basedir/$log
send "show running\r"
expect {
"$prompt" {
log_file
send_user "\nConfiguration Downloaded\n"
}
timeout {
send_user "\nError during configuration download."
set mailfail "Error during configuration download."
}
}
close
if { $mailfail != "" } {
exec /bin/mail -s$mailsubject $mailto << "
$mailfail"
exit
}

Step 6: Check File Size

Check the filesize.

set filesize [file size $basedir/$log]
if { $filesize <= 512 } {
send_user "Netscreen config is too small, please investigate\n"
set mailfail "Netscreen config is too small, please investigate\n"
exec /bin/mail -s$mailsubject $mailto << "
$mailfail"
exit

}

Step 7: Cleanup

Clean up configs older than two weeks.

#Remove config older than 2 weeks
exec find $basedir -name '*config.txt*' -mtime +14

Step 8: Put It All Together

Put it all together. The script is attached, it will email on failures.