Advertisement
Guest User

Untitled

a guest
Apr 7th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. #!/bin/bash
  2. rw_community="COMUNITYLOL"
  3. backup_dir="/home/LOL-backup";
  4. server="10.10.110.10"
  5. ftpuser="LOL-backup"
  6. ftppassw="ahuenno"
  7. switch_user="LOL-backup"
  8. switch_password="pwdtoswitch"
  9. log="/home/LOL-backup/log/LOL-backup.log";
  10. date=`date +"%F %R"`;
  11. if [ -z "$1" ]; then
  12. #echo "Usage: $0 <hostname> <platform>";
  13. exit 0;
  14. fi
  15.  
  16. function cisco_copy_config {
  17. var=`snmpget -v2c -c $rw_community -Oqvn $2 .1.3.6.1.2.1.1.5.0`
  18. if [ $? != 0 ]; then
  19. echo "$date $2 Backup config failed, host is down or not accept snmp comunity" >> $log;
  20. exit 0;
  21. fi
  22. snmpset -c $rw_community -v2c $2 .1.3.6.1.4.1.9.9.96.1.1.1.1.2.$1 i 2 \
  23. .1.3.6.1.4.1.9.9.96.1.1.1.1.3.$1 i 4 \
  24. .1.3.6.1.4.1.9.9.96.1.1.1.1.4.$1 i 1 \
  25. .1.3.6.1.4.1.9.9.96.1.1.1.1.5.$1 a $server \
  26. .1.3.6.1.4.1.9.9.96.1.1.1.1.6.$1 s $3 \
  27. .1.3.6.1.4.1.9.9.96.1.1.1.1.7.$1 s $ftpuser \
  28. .1.3.6.1.4.1.9.9.96.1.1.1.1.8.$1 s $ftppassw \
  29. .1.3.6.1.4.1.9.9.96.1.1.1.1.14.$1 i 4 2>&1 > /dev/null
  30. sleep 2
  31. status=`snmpget -v2c -c $rw_community -Oqvn $2 1.3.6.1.4.1.9.9.96.1.1.1.1.10.$1`
  32. while [ "$status" -eq "2" ]
  33. do
  34. sleep 2
  35. status=`snmpget -v2c -c $rw_community -Oqvn $2 1.3.6.1.4.1.9.9.96.1.1.1.1.10.$1`
  36. done
  37. 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
  38. # if [ "$status" -eq "4" ]; then
  39. # echo "Backup config failed for host $2"
  40. # exit 1
  41. # fi
  42. }
  43.  
  44.  
  45.  
  46. function huawei_vrp8_copy_config {
  47. host=${1^^}
  48. wget -t 3 ftp://$switch_user:$switch_password@$host/vrpcfg.zip -O $backup_dir/$host.zip -q
  49. unzip -p $backup_dir/$host.zip > $backup_dir/$host
  50. rm -f $backup_dir/$host.zip
  51. }
  52.  
  53.  
  54. function juniper_copy_config {
  55. host=${1^^}
  56. archive=($(ls $backup_dir/$host*.conf.gz* -t 2>/dev/null))
  57. if [ -n "${archive[0]}" ]; then
  58. mv ${archive[0]} $backup_dir/$host.conf.gz
  59. gzip -dc $backup_dir/$host.conf.gz > $backup_dir/$2
  60. rm -f $backup_dir/$host*.conf.gz*
  61. sed -i -e '1d' $backup_dir/$2
  62. else
  63. echo "$date Info(not error, debug only): No backup files with mask $host*.conf.gz*" >> $log
  64. fi
  65. }
  66.  
  67. function check_backup_exist {
  68. if [ ! -f $backup_dir/$1 ]
  69. then
  70. echo "$date Backup file $1 not exist" >> $log
  71. exit 0;
  72. else
  73. modified=`date -r $backup_dir/$1 +%s`
  74. now=`date +%s`
  75. diff=$[$now-$modified]
  76. if [ "$diff" -gt "86400" ]; then
  77. echo "$date Backup error! file $1 older 1 days. Created `date -r $backup_dir/$1 +%H:%M-%d/%m/%Y`" >> $log
  78. exit 0
  79. fi
  80. fi
  81. }
  82.  
  83. function check_filesize {
  84. filesize=`stat -c%s $backup_dir/$1`
  85. if (( $filesize < "100" )) ; then
  86. echo "$date File size $1 is very small! $filesize bytes" >> $log
  87. exit 0
  88. fi
  89. if (( $filesize > "1024000" )) ; then
  90. echo "$date File size $1 is very big! $filesize bytes" >> $log
  91. exit 0
  92. fi
  93. }
  94.  
  95.  
  96. RANGE=999
  97. rand=$RANDOM
  98. let "rand %= $RANGE"
  99.  
  100. host=${1^^}
  101. file=$host
  102. platform=${2^^}
  103. #ios
  104. if [ $platform = "IOS" ] || [ $platform = "IOS-XR" ] ; then
  105. cisco_copy_config $rand $host $file
  106. check_backup_exist $file
  107. check_filesize $file
  108.  
  109. fi
  110.  
  111. #nxos, xos
  112. if [ $platform = "NX-OS" ] || [ $platform = "XOS" ] ; then
  113. cisco_copy_config $rand $host $file
  114. check_backup_exist $file
  115. check_filesize $file
  116.  
  117. fi
  118. #huawei vrp8
  119. if [ $platform = "VRP8" ]; then
  120. huawei_vrp8_copy_config $host $file
  121. check_backup_exist $file
  122. check_filesize $file
  123. fi
  124.  
  125. #junos
  126. if [ $platform = "JUNOS" ] ; then
  127. juniper_copy_config $host $file
  128. check_backup_exist $file
  129. check_filesize $file
  130. fi
  131. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement