Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- rw_community="COMUNITYLOL"
- backup_dir="/home/LOL-backup";
- server="10.10.110.10"
- ftpuser="LOL-backup"
- ftppassw="ahuenno"
- switch_user="LOL-backup"
- switch_password="pwdtoswitch"
- log="/home/LOL-backup/log/LOL-backup.log";
- date=`date +"%F %R"`;
- if [ -z "$1" ]; then
- #echo "Usage: $0 <hostname> <platform>";
- exit 0;
- fi
- function cisco_copy_config {
- var=`snmpget -v2c -c $rw_community -Oqvn $2 .1.3.6.1.2.1.1.5.0`
- if [ $? != 0 ]; then
- echo "$date $2 Backup config failed, host is down or not accept snmp comunity" >> $log;
- exit 0;
- fi
- snmpset -c $rw_community -v2c $2 .1.3.6.1.4.1.9.9.96.1.1.1.1.2.$1 i 2 \
- .1.3.6.1.4.1.9.9.96.1.1.1.1.3.$1 i 4 \
- .1.3.6.1.4.1.9.9.96.1.1.1.1.4.$1 i 1 \
- .1.3.6.1.4.1.9.9.96.1.1.1.1.5.$1 a $server \
- .1.3.6.1.4.1.9.9.96.1.1.1.1.6.$1 s $3 \
- .1.3.6.1.4.1.9.9.96.1.1.1.1.7.$1 s $ftpuser \
- .1.3.6.1.4.1.9.9.96.1.1.1.1.8.$1 s $ftppassw \
- .1.3.6.1.4.1.9.9.96.1.1.1.1.14.$1 i 4 2>&1 > /dev/null
- sleep 2
- status=`snmpget -v2c -c $rw_community -Oqvn $2 1.3.6.1.4.1.9.9.96.1.1.1.1.10.$1`
- while [ "$status" -eq "2" ]
- do
- sleep 2
- status=`snmpget -v2c -c $rw_community -Oqvn $2 1.3.6.1.4.1.9.9.96.1.1.1.1.10.$1`
- done
- snmpset -c $rw_community -v2c $host .1.3.6.1.4.1.9.9.96.1.1.1.1.14.$1 i 6 2>&1 > /dev/null
- # if [ "$status" -eq "4" ]; then
- # echo "Backup config failed for host $2"
- # exit 1
- # fi
- }
- function huawei_vrp8_copy_config {
- host=${1^^}
- wget -t 3 ftp://$switch_user:$switch_password@$host/vrpcfg.zip -O $backup_dir/$host.zip -q
- unzip -p $backup_dir/$host.zip > $backup_dir/$host
- rm -f $backup_dir/$host.zip
- }
- function juniper_copy_config {
- host=${1^^}
- archive=($(ls $backup_dir/$host*.conf.gz* -t 2>/dev/null))
- if [ -n "${archive[0]}" ]; then
- mv ${archive[0]} $backup_dir/$host.conf.gz
- gzip -dc $backup_dir/$host.conf.gz > $backup_dir/$2
- rm -f $backup_dir/$host*.conf.gz*
- sed -i -e '1d' $backup_dir/$2
- else
- echo "$date Info(not error, debug only): No backup files with mask $host*.conf.gz*" >> $log
- fi
- }
- function check_backup_exist {
- if [ ! -f $backup_dir/$1 ]
- then
- echo "$date Backup file $1 not exist" >> $log
- exit 0;
- else
- modified=`date -r $backup_dir/$1 +%s`
- now=`date +%s`
- diff=$[$now-$modified]
- if [ "$diff" -gt "86400" ]; then
- echo "$date Backup error! file $1 older 1 days. Created `date -r $backup_dir/$1 +%H:%M-%d/%m/%Y`" >> $log
- exit 0
- fi
- fi
- }
- function check_filesize {
- filesize=`stat -c%s $backup_dir/$1`
- if (( $filesize < "100" )) ; then
- echo "$date File size $1 is very small! $filesize bytes" >> $log
- exit 0
- fi
- if (( $filesize > "1024000" )) ; then
- echo "$date File size $1 is very big! $filesize bytes" >> $log
- exit 0
- fi
- }
- RANGE=999
- rand=$RANDOM
- let "rand %= $RANGE"
- host=${1^^}
- file=$host
- platform=${2^^}
- #ios
- if [ $platform = "IOS" ] || [ $platform = "IOS-XR" ] ; then
- cisco_copy_config $rand $host $file
- check_backup_exist $file
- check_filesize $file
- fi
- #nxos, xos
- if [ $platform = "NX-OS" ] || [ $platform = "XOS" ] ; then
- cisco_copy_config $rand $host $file
- check_backup_exist $file
- check_filesize $file
- fi
- #huawei vrp8
- if [ $platform = "VRP8" ]; then
- huawei_vrp8_copy_config $host $file
- check_backup_exist $file
- check_filesize $file
- fi
- #junos
- if [ $platform = "JUNOS" ] ; then
- juniper_copy_config $host $file
- check_backup_exist $file
- check_filesize $file
- fi
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement