Thursday, June 2, 2011

How to schedule backup of Brocade SAN switch configuration on UNIX/Linux

Brocade SAN switch can be backed up using Web tools or using CLI over SSH.
We can also schedule backup up of configuration.


Here is how to backup switch configuration from UNIX over SSH and SCP.

1, Generate key pair on switch as admin user:
SANSW:admin> sshutil genkey -rsa

2, Generate key pair on host as user used for backing up configuration (if you don't have it).
username@host:# ssh-keygen -t rsa -P ""



3, Import public key from host to switch
SANSW:admin> sshutil importpubkey
Enter user name for whom key is imported:admin
Enter IP address:10.10.10.10
Enter remote directory:/home/username/.ssh
Enter public key name(must have .pub suffix):id_rsa.pub
Enter login name:username
username@HOSTNAME's password:
public key is imported successfully.

4, Export public key from switch to host
SANSW:admin> sshutil exportpubkey
Enter IP address:10.10.10.10
Enter remote directory:/home/username/.ssh
Enter login name:username
sanadmin@HOSTNAME's password:
public key out_going.pub is exported successfully.

5, Add switch admin's public key to user's authorized_keys on host
username@host:# cat /home/username/.ssh/out_going.pub >> /home/username/.ssh/authorized_keys
Notice: FOS 7 creates different name for out_going.pub file => out_going_SANSWHOSTNAME.pub

You can create scheduled task in crontab to backup config once a day and send it to TSM:
0 1 * * * su - username /path_to_backup_dir/script.sh

======================
#!/bin/ksh
# Script to back up SAN configuration using  ssh and scp.

# Variable declaration
RC=0
SUMRC=0
SAN_LIST="SAN_SW1 SAN_SW2 SAN_SW3"
BCKSRV="IP_OF_BACKUP_SERVER|"
BCK_DIRECTORY="/directory/where/to/backup"
BCK_USER=BACKUP_SERVER_USER
#TODAY=`date +"%Y%m%d"`

for san in $SAN_LIST
do
  echo "Backing up SAN switch config data..." $san
  ssh -ax admin@$san "bash --login -c \"configupload -scp $BCKSRV,$BCK_USER,$BCK_DIRECTORY/$san.cfg\""
  RC=$?
  echo "RC = " $RC
  SUMRC=$((SUMRC+RC))
done

#TSM backup
echo "Archiving configuration of all SAN switches..."
dsmc archive "$BCK_DIRECTORY/*" -archmc=MC_NAME
RC=$?
echo "RC = " $RC
SUMRC=$((SUMRC+RC))

exit $SUMRC
======================

Note:
There is the difference between FOS version in the way how to run commands remotely over ssh.

FOS 6.1.0c (maybe versions bellow)
ssh -ax admin@$san "bash --login -c \"configupload -scp $BCKSRV,$BCK_USER,$BCK_DIRECTORY/$san.cfg\""

FOS v6.4.2a and higher
ssh admin@$san "configupload -scp $BCKSRV,$BCK_USER,$BCK_DIRECTORY/$san.cfg"

That's all.

1 comment: