Quantcast
Channel: THE SAN GUY
Viewing all articles
Browse latest Browse all 214

Automating Config / Zone backups for Brocade Switches

$
0
0

I was looking for an easy way to make backups of our fabric and report the status of the backup on our internal web page. I wrote a script that will remotely run configupload and pull the script config file from all the switches via FTP, move the previous config file to an archive location, create a report of the output and copy it to a web page folder. I run the bash script using cygwin on our internal IIS server, and it’s scheduled to run daily.

The script uses ssh, so you could either set up ssh keys or use an opensource package called sshpass (http://sourceforge.net/projects/sshpass). In this example script I’m using sshpass to avoid having to type in a password for each command when the script runs.

I figured out that you must connect to a new switch at least once manually without using sshpass, as it supresses the output that asks you to confirm adding it as a known host. Below is the output, I simply ran a ‘zoneshow’ as the initial command to set it up.

$ ssh USERID@brocade_switch_1 zoneshow
 The authenticity of host ‘brocade_switch_1 (10.0.0.9)’ can’t be established.
 DSA key fingerprint is 3b:cd:98:62:4a:67:99:28:c4:41:f3:19:8d:f1:7d:a0.
 Are you sure you want to continue connecting (yes/no)? yes
 Warning: Permanently added ‘brocade_switch_1,10.0.0.9′ (DSA) to the list of known hosts.

My original script is set up to run for multiple geographical locations which is why I have separate lists set up.   This sample script is set up for two separate theoretical locations, it could easily be expanded or reduced based on your environment.

#Set Environment 
TODAY=`date`
TIMESTAMP=`date +”%Y%m%d%H%M”`
LOCALPATH=”/cygdrive/c/scripts/brocade”
WEBPATH=”/cygdrive/c/inetpub/wwwroot”
FTPHOST=”10.0.0.1″
FTPUSER=”ftpuser”
FTPPATH=”/brocade”
FTPPASSWORD=”password”

#Add timestamp to top of report
echo $TODAY > $WEBPATH/brocade_backup_report.txt
echo ” ” >> $WEBPATH/brocade_backup_report.txt

#Clear data from last run
>$LOCALPATH/brocade_backup_report_1.txt
>$LOCALPATH/brocade_backup_report_2.txt

#Move yesterday’s backups to an archive location
mv $WEBPATH/brocade/*.txt /cygdrive/e/archive/brocade

#List of Switches to be backed up
SWITCHLIST1=”switch1siteA switch2siteA switch3siteA switch4siteA”
SWITCHLIST2=”switch1siteB switch2siteB switch3siteB switch4siteB switch5siteB switch6siteB”

for x in $SWITCHLIST1
do
echo “$x”: “$FTPPATH/$x.$TIMESTAMP” >> $LOCALPATH/brocade_backup_report_1.txt
sshpass -p ‘password’ ssh admin@$x configupload -ftp $FTPHOST,$FTPUSER,$FTPPATH/$x.$TIMESTAMP.txt,$FTPPASSWORD >> $LOCALPATH/brocade_backup_report_1.txt
echo ” ” >> $LOCALPATH/brocade_backup_report_1.txt
done

for x in $SWITCHLIST2
do
echo “$x”: “$FTPPATH/$x.$TIMESTAMP” >> $LOCALPATH/brocade_backup_report_2.txt
sshpass -p ‘password’ ssh USERID@$x configupload -ftp $FTPHOST,$FTPUSER,$FTPPATH/$x.$TIMESTAMP.txt,$FTPPASSWORD >> $LOCALPATH/brocade_backup_report_2.txt
echo ” ” >> $LOCALPATH/brocade_backup_report_2.txt
done

# This last section creates the report for the web page.
cat $LOCALPATH/brocade_backup_report_1.txt.txt $LOCALPATH/brocade_backup_report_2.txt.txt >> $WEBPATH/brocade_backup_report.txt

The report output looks like this:

Thu Sep 12 06:00:01 CDT 2013
 
switch1siteA: /brocade/switch1siteA.201309120600
configUpload complete: All selected config parameters are uploaded
 
switch2siteA: /brocade/switch2siteA.201309120600
configUpload complete: All selected config parameters are uploaded
 
switch3siteA: /brocade/switch3siteA.201309120600
configUpload complete: All selected config parameters are uploaded
 
switch4siteA: /brocade/switch4siteA.201309120600
configUpload complete: All selected config parameters are uploaded
 
switch1siteB: /brocade/switch1siteB.201309120600
configUpload complete: All selected config parameters are uploaded
 
switch2siteB: /brocade/switch2siteB.201309120600
configUpload complete: All selected config parameters are uploaded
 
switch3siteB: /brocade/switch3siteB.201309120600
configUpload complete: All selected config parameters are uploaded
 
switch4siteB: /brocade/switch4siteB.201309120600
configUpload complete: All selected config parameters are uploaded
 
switch5siteB: /brocade/switch5siteB.201309120600
configUpload complete: All selected config parameters are uploaded
 
switch6siteB: /brocade/switch6siteB.201309120600
configUpload complete: All selected config parameters are uploaded


Viewing all articles
Browse latest Browse all 214

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>