-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup_net_dcdevices.sh
185 lines (156 loc) · 5.28 KB
/
backup_net_dcdevices.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/bin/bash
EmailAddress="sysadmin@icontrol.com"
BACKUP_LOC="/data/www/network_dc_configs/configs/"
WEB_LOC="/data/www/network_dc_configs/web/"
DATE=`date -d "Yesterday" +"%m-%d-%Y_%H"`
SIZE="2000"
ERROR="N"
PIX="pix-config"
SWITCH="switch-config"
CSS="css-config"
DEVICES="pix css switch"
ADMIN="admin1 controlmon1"
CMD_LOC="/usr/local/sbin/"
REMOTE_DUMP="/data/network_configs/"
REMOTE_WEBCMD="nipper "
for cAdmin in $ADMIN
do
echo "Grabbing the list of network devices for ${cAdmin}"
perl -e "print '-' x 50"
LOGIN=""
if [ -d "${BACKUP_LOC}${cAdmin}/current" ]; then
#Do Nothing
echo ""
else
echo ""
echo "Creating directory ${BACKUP_LOC}${cAdmin}/current"
mkdir -pv ${BACKUP_LOC}${cAdmin}/current
echo ""
fi
if [ -d "${BACKUP_LOC}${cAdmin}/previous" ]; then
#Do Nothing
echo ""
else
echo ""
echo "Creating directory ${BACKUP_LOC}${cAdmin}/previous"
mkdir -pv ${BACKUP_LOC}${cAdmin}/previous
echo ""
fi
if [ -d "${BACKUP_LOC}${cAdmin}/archive" ]; then
#Do Nothing
echo ""
else
echo ""
echo "Creating directory ${BACKUP_LOC}${cAdmin}/archive"
mkdir -pv ${BACKUP_LOC}${cAdmin}/archive
echo ""
fi
#########################################
# PIX
#########################################
echo "PIX List (${cAdmin}):"
LIST=`ssh ${LOGIN}${cAdmin} "cat ${CMD_LOC}${PIX}.list" | cut -d"|" -f 1 | grep -v "^$"`
echo $LIST | sed -e "s/ /\n/g"
echo ""
echo "Sending PIX configurations to ${cAdmin}"
EXECUTE_CMD=`ssh ${LOGIN}${cAdmin} "${CMD_LOC}${PIX}.pl"`
$EXECUTE_CMD
echo "Done."
echo ""
##########################################
# CSS
##########################################
echo "CSS List (${cAdmin}):"
CLIST=`ssh ${LOGIN}${cAdmin} "cat ${CMD_LOC}${CSS}.list" | cut -d"|" -f 1 | grep -v "^$"`
echo $CLIST | sed -e "s/ /\n/g"
echo ""
echo "Sending CSS configurations to ${cAdmin}"
EXECUTE_CMD=`ssh ${LOGIN}${cAdmin} "${CMD_LOC}${CSS}.pl"`
$EXECUTE_CMD
echo "Done."
echo ""
##########################################
# SWITCH
##########################################
echo "SWITCH List (${cAdmin}):"
SLIST=`ssh ${LOGIN}${cAdmin} "cat ${CMD_LOC}${SWITCH}.list" | cut -d"|" -f 1 | grep -v "^$"`
echo $SLIST | sed -e "s/ /\n/g"
echo ""
echo "Sending SWITCH configurations to ${cAdmin}"
EXECUTE_CMD=`ssh ${LOGIN}${cAdmin} "${CMD_LOC}${SWITCH}.pl"`
$EXECUTE_CMD
echo "Done."
echo ""
###########################################
perl -e "print '#' x 50" ; echo ""
LIST="${LIST} ${CLIST} ${SLIST}"
for cFile in $LIST
do
if [ `echo ${cFile} | cut -d "-" -f 2` == "pix" ]; then
DEVICES="pix"
else
if [ `echo ${cFile} | cut -d "-" -f 2` == "css" ]; then
DEVICES="css"
else
if [ `echo ${cFile} | cut -d "-" -f 2` == "sw48" ]; then
DEVICES="switch"
else
if [ `echo ${cFile} | cut -d "-" -f 2` == "sw24" ]; then
DEVICES="switch"
fi
fi
fi
fi
OLD_FILE="${BACKUP_LOC}${cAdmin}/previous/${cFile}"
if [ -f "${BACKUP_LOC}${cAdmin}/current/${cFile}" ]; then
echo "Moving current file ${cFile} to previous"
mv -v ${BACKUP_LOC}${cAdmin}/current/${cFile} ${OLD_FILE}
NOPREV="N"
else
NOPREV="Y"
fi
echo "Getting Current File"
scp ${LOGIN}${cAdmin}:${REMOTE_DUMP}${DEVICES}/current/${cFile} ${BACKUP_LOC}${cAdmin}/current/
echo ""
if [ ${NOPREV} == "Y" ]; then
#Do Nothing
echo "No Previous Configuration"
perl -e "print '#' x 50" ; echo ""
else
echo "Checking for differences:"
echo "-------------------------"
diff ${BACKUP_LOC}${cAdmin}/current/${cFile} ${OLD_FILE}
echo "-------------------------"
#echo "Compressing ${OLD_FILE}..."
#gzip "$OLD_FILE"
#echo "Done."
FILE_SIZE=`ls -l ${BACKUP_LOC}${cAdmin}/current/${cFile} | awk '{print $5}'`
if [ ${FILE_SIZE} -lt ${SIZE} ] ; then
echo "*******"
echo "*ERROR* ${cFile} file size is less than ${SIZE}"
echo "*******"
ERROR="Y"
fi
perl -e "print '#' x 50" ; echo ""
if [ ${ERROR} == "Y" ]; then
echo "*ERROR* file size is less than ${SIZE}, check the cron backup email for more info" | /bin/mail -s "DataCenter Net Config Error" $EmailAddress
fi
fi
done
echo "Verifying directory is not empty"
cd ${BACKUP_LOC}${cAdmin}/previous/
if [ `ls -la | wc -l` -gt 4 ]; then
echo "Passed."
echo ""
echo "Tarring ${BACKUP_LOC}${cAdmin}/previous/"
tar --remove-files -cvzf ../archive/configs_${cAdmin}_${DATE}.tar.gz ${LIST}
echo "Done."
echo ""
echo "Final Tar:"
echo "----------"
ls -l ../archive/configs_${cAdmin}_${DATE}.tar.gz
echo ""; echo ""; echo "";
else
echo "Failed. The directory is to empty"
fi
done