cancel
Showing results for 
Search instead for 
Did you mean: 

UPM script to backup switch configuration and policies etc

UPM script to backup switch configuration and policies etc

EtherNation_Use
Contributor II
Create Date: Jan 4 2012 4:15AM

Hi!

Enclosed is a UPM script we've been using for a while to backup XOS switches. We've used it on 450/460/BD10K etc. I think I'll require XOS 12.4.

It backs up the current config both as text and xml. It also backs up other files like .pol or .xsf. The files are stored on a tftp server, in a separate directory for each day (you have to create the directory structure with a script on the tftp server - included below). In our setup the the tftp root for the backups is /data/tftpboot/switchbackup/

Date and switch name are prepended to each file name (eg a123a-2012-01-03.cfg and a123a-2012-01-03.txt for XML and text versions).

We use the script to backup files to two different tftp servers - you'll have to enter your own ip address(es).

The script tries to intelligently decide to use the correct VR for the tftp command (vr-default or vr-management).

The script is first run 12 hours after reboot and then every 24 hours.





UPM SCRIPT:

create upm profile backup-config

configure cli mode scripting abort-on-error

set var CLI.OUT 0

set var tftproot switchbackup

show iproute vr vr-mgmt

set var input $TCL(split ${CLI.OUT} " ")

set var x $TCL(lsearch -glob $input "*Total number of routes = 0*")

if ($x == -1) then

set var vr "vr-mgmt"

else

set var vr "vr-default"

endif

set var seconds $TCL(clock seconds)

set var date $TCL(clock format $seconds -format {%Y-%m-%d})

show switch

set var input $TCL(split ${CLI.OUT} " ")

set var x $TCL(lsearch -glob $input "*SysName*")

set var x $TCL(lindex $input $x)

set var x $TCL(split $x " ")

set var switchname $TCL(lindex ${x} 10)

set var x $TCL(lsearch -glob $input "*Config Selected*")

set var x $TCL(lindex $input $x)

set var x $TCL(split $x " ")

set var y $TCL(lsearch -glob $x "*.cfg*")

set var config $TCL(lindex ${x} $y)

save configuration

configure cli mode scripting ignore-error

tftp put 10.1.1.120 vr $vr $(config) $(tftproot)/$(date)/$(switchname)-$(date).cfg

tftp put 10.1.1.130 vr $vr $(config) $(tftproot)/$(date)/$(switchname)-$(date).cfg

upload configuration 10.1.1.120 $(tftproot)/$(date)/$(switchname)-$(date).txt vr $vr

upload configuration 10.1.1.130 $(tftproot)/$(date)/$(switchname)-$(date).txt vr $vr

configure cli mode scripting abort-on-error

ls

set var files $TCL(split ${CLI.OUT} " ")

set var n $TCL(llength $files)

set var n $TCL(expr {$n-5})

set var files $TCL(lrange $files 0 $n)

while ($n != -1) do

set var line $TCL(lindex $files $n)

set var filename $TCL(lindex $line end)

set var exempt $TCL(list license.xlic vmt)

set var suffix $TCL(string match "*cfg" $line)

if ($suffix == 0) then

set var dobackup $TCL(lsearch $exempt $filename)

if ($dobackup == -1) then

configure cli mode scripting ignore-error

tftp put 10.1.1.120 vr $vr $(filename) $(tftproot)/$(date)/$(switchname)-$(date)_$(filename)

tftp put 10.1.1.130 vr $vr $(filename) $(tftproot)/$(date)/$(switchname)-$(date)_$(filename)

configure cli mode scripting abort-on-error

endif

endif

set var n ($n-1)

endwhile

.



UPM CONFIG:

configure upm profile backup-config maximum execution-time 240

create upm timer backup-config-timer

configure upm timer backup-config-timer profile backup-config

configure upm timer backup-config-timer after 43200 every 86400

enable upm profile backup-config



UNIX SCRIPT TO CREATE DIRECTORIES



#!/bin/sh

#

# Create empyt directories for next 5 days

# used to store backup of switch configuration

#

basedir='/data/tftpboot/switchbackup'

today='date +'%s''

for i in 0 1 2 3 4 5; do

nextday='expr $i \* 86400 + $today'

mkdir -m 777 $basedir/'date +'%F' --date "1970-01-01 $nextday sec"'

done



(from Roland_Mansson)
1 REPLY 1

EtherNation_Use
Contributor II
Create Date: Jan 4 2012 8:37AM

Macrm,

Great contribution! This can benefit anyone who has not commited to Ridgeline or Epicenter yet.

(from john_padilla)
GTM-P2G8KFN