-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmissed_full_weekend_backups_2.pl
269 lines (263 loc) · 9.67 KB
/
missed_full_weekend_backups_2.pl
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#!/usr/bin/perl -w
# Used to determine which fulls failed from the previous Friday
# Peter Reed (aVenture)
# 11 29, 2016
# 1.08
# Determine the group, backup command, and scheduled backup
(@servers) = ('sscprodeng', 'sscprodeng2');
$val = ". type:NSR client'\n'show name\\;group\\;backup command\\;scheduled backup\\;comment\\;action'\n'print";
print "Before nsradmin\n";
foreach $networker (@servers) {
(@return) = `/usr/bin/echo $val | /usr/sbin/nsradmin -s $networker -i -`;
print "After nsradmin on $networker\n";
# Client name is mixed case so lower case the names
print "Determing regular/VADP, Prod/Non Prod, Scheduled/Not scheduled on $networker\n";
foreach $val (@return) {
chomp $val;
$val =~ s/\;//;
next if $val =~ /^\s*$/;
if ($val =~ /name:/) {
$val =~ s/\s*name: //;
$name = lc($val);
} elsif ($val =~ /backup command/) {
$val =~ s/\s*backup command: //;
$backup_command{$name} = grep (/nsrvadp/,$val);
} elsif ($val =~ /group/) {
$val =~ s/\s*group: //;
$group{$name} = $val;
## Keep tract of current groups for later
#$current_groups{$val} = 1;
} elsif ($val =~ /scheduled backup/) {
$val =~ s/\s*scheduled backup: //;
if (!defined $scheduled_backup{$name}) { $scheduled_backup{$name} = 0};
# only care is server is enabled
if ( grep(/Enabled/,$val) ) {
# found one previously
if ($scheduled_backup{$name} =~ /ssc/) {
# Special case for multiple definitions for same client
if ($scheduled_backup{$name} ne $networker) {print "****Client $name $scheduled_backup{$name} is enabled on multiple servers\n"};
} else {
$scheduled_backup{$name} = $networker;
}
}
} elsif ($val =~ /comment/) {
$val =~ s/\s*comment: //;
$comment{$name} = $val;
}
}
}
#(@totalsize) = `mminfo -xc, -m'`;
foreach $networker (@servers) {
print "Determing all clients from the last three weeks on server $networker\n";
(@backup_clients)=`/usr/sbin/mminfo -xc, -s $networker -r client -q 'savetime>three weeks ago' | /usr/bin/sort | /usr/bin/uniq`;
foreach $client (@backup_clients) {
chomp $client;
$client = lc($client);
$grouper{$client} = 1;
}
}
#/usr/sbin/mminfo -xc, -a -o ct -r client,savetime,name -q 'savetime>last friday,level=full'
foreach $networker (@servers) {
print "Determining clients with full backups since last Friday on server $networker\n";
(@backup_full ) = `/usr/sbin/mminfo -xc, -a -o ct -s $networker -r 'client,savetime,totalsize' -q 'savetime>last friday,level=full' | /usr/bin/sort | /usr/bin/uniq`;
undef %full_backup;
foreach $val (@backup_full) {
chomp $val;
next if ($val=~/lient/);
next if ($val=~/^\s*$/);
next if ($val=~/invalid client name/);
($client,$savetime,$totalsize) = split(/,/,$val);
$client = lc($client);
$key = "$client:$savetime";
if (defined $server_size{$key}) {
$server_size{$key} += $totalsize;
} else {
$server_size{$key} = $totalsize;
}
}
}
# Process through to determine the maximum size backed up in a day
# This is to handle multiple failed fulls
foreach $key (sort keys %server_size) {
($client,$savetime) = split(/:/,$key);
if (defined $full_backup{$client} ) {
if ( $server_size{$key} >$full_backup{$client} ) {$full_backup{$client} = $server_size{$key}};
} else {
# Assume that 3G is smallest server
if ($comment{$client} =~ /F:/) {
($check_size) = $comment{$client} =~ /.*F:(\d*\.*\d*)\;.*/;
$check_size = $check_size*1000000;
} else {
$check_size=3000000000;
}
if ($server_size{$key} > $check_size) { $full_backup{$client} = $server_size{$key} }
}
}
#print "Begin full backup\n";
#foreach $val (sort keys %full_backup) {
# print "Server = $val, size=$full_backup{$val}\n";
#}
print "Processing Client list\n";
# Loop through the clients
foreach $client (sort keys %grouper) {
next if (defined $full_backup{$client});
$ping = pinger($client);
if ($ping =~ /up/) {
$port = testport($client,7937);
} else {
$port = 'Client not listening';
}
if (!defined $comment{$client}) {
print "*** Client $client comment not defined\n";
$comment{$client} = '';
}
if ($comment{$client} !~ /D:/) {
$dns = resolv_name($client);
if ($dns =~ /In DNS/) {
if ($ping =~ /up/) {
if ($port =~ /Client listening/) {
if (defined $scheduled_backup{$client}) {
if ($scheduled_backup{$client} =~ /ssc/) {
$lower = lc($group{$client});
$networker_server = $scheduled_backup{$client};
next if $lower =~ /decom/;
if ( $lower =~ /prod/) {
if ( $backup_command{$client} == 1) {
$return = append_group('Automated-PROD-VADP-Reruns',$client,$networker_server);
} else {
$return = append_group('Automated-PROD-Reruns',$client,$networker_server);
}
print "****PROD Client $client, no full backups since last Friday, $ping, $dns, $port\n";
} else {
if ( $backup_command{$client} == 1 ) {
$return = append_group('Automated-NON-PROD-VADP-Reruns',$client,$networker_server);
} else {
$return = append_group('Automated-NON-PROD-Reruns',$client,$networker_server);
}
print "****NON PROD Client $client, no full backups since last Friday, $ping, $dns, $port\n";
}
} else {
print "*** Client $client is not scheduled for backups\n";
}
}
} else {
print "*** Client $client is not listening on port 7937\n";
}
} else {
print "*** Client $client is down\n";
}
} else {
print "*** Client $client not in DNS\n";
}
} else {
print "*** Client $client is marked as DCOM'd, $ping, $dns, $port\n";
if ( $group{$client} !~ /DECOM/ ) { print " Not in DECOM group\n"};
if ( $scheduled_backup{$client} == 1 ) { print " Not disabled\n"};
}
}
#sub format_number {
# my ($val,$places,$justify,$width) = @_;
# my $text1;
# $text=reverse $val;
# $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
# $val=reverse $text;
# $val =~ s/(\d*\.\d{$places})\d*/$1/;
# $length = length($val);
# if ($justify eq 'l') {
# $start = 0;
# } elsif ($justify eq 'c') {
# $start = int( ($width-$length)/2 );
# } elsif ( $justify eq 'r') {
# $start = $width-$length;
# } else {
# print "Error in formatnumber\n";
# }
# $final = ' ' x $width;
# substr($final,$start,$length)=$val;
# return $final;
#}
sub pinger{
($pingee) = @_;
$up = 'down';
# Test to see if machine is up
$ping = `/usr/sbin/ping $pingee 5 2>/dev/null`;
if ($ping =~ /is alive/) {$up=' up'};
return $up;
}
sub testport{
($host,$port) = @_;
use IO::Socket;
$| = 1; # Flush Buffer immediately
$socket = IO::Socket::INET->new(PeerAddr => $host, PeerPort =>$port, Timeout => 5);
if ($socket) {
$return = " Client listening";
} else {
$return = "Client not listening";
}
}
sub resolv_name {
my ($check) = @_;
$return = "Not in DNS";
push(@DNS,'192.168.104.240','192.168.104.241','192.168.104.56','192.168.104.57');
push(@SUF,'sscnola.oob','sscnola.oob','cdc.local','cdc.local');
my $index =-1;
foreach $dns (@DNS) {
$index+=1;
my (@dum) = `/usr/sbin/nslookup $check.$SUF[$index] $dns`;
$bc =0;
foreach $val (@dum) {
#$val =~ s/\s//g;
chomp $val;
if ( $bc == 1 ) {
if ( $val =~ /Address:/ ) {
$return = " In DNS";
goto RETURN;
} else {
print "problem in nslookup\n";
}
}
if ($val =~ /can't find $check/ ) {
goto RETURN;
} elsif ($val =~ /Name:/) {
$bc=1;
}
}
}
RETURN:
return $return;
}
sub append_group {
my ($group,$clnt,$networker_server) = @_;
#my $a = 1;
#if ($a == 1) {return};
#foreach $clnt (@clients) {
chomp $clnt;
print "Client=$clnt added to group $group on $networker_server\n";;
# Create clients in $group and INDEX ignoring the current group
$val = ". type: NSR client\\;name:$clnt'\n'append group:$group'\n'";
(@return) = `/usr/bin/echo $val | /usr/sbin/nsradmin -s $networker_server -i - `;
foreach $vvv (@return) {
print "INFO: $vvv\n";
}
#}
}
sub update_group {
my ($grp,$list,%group) = @_;
my (@clients) = split(/:/,$list);
foreach $clnt (@clients) {
# Create clients in $group and INDEX ignoring the current group
if (!defined $group{$clnt}) {
print RAP "GROUP_MOVE - backup client $clnt doesn't exist in group $grp\n";
} else {
next if $group{$clnt} =~ /$grp/;
print RAP "GROUP_MOVE - client $clnt moved from group $group{$clnt} to group $grp\n";
print "GROUP_MOVE - client $clnt moved from group $group{$clnt} to group $grp\n";
$val = ". type: NSR client\\;name:$clnt'\n'update group:INDEX, $grp'\n'";
print "Val in update=$val\n";
(@return) = `/usr/bin/echo $val | /usr/sbin/nsradmin -i - `;
foreach $vvv (@return) {
print RAP "\tINFO: $vvv\n";
}
}
}
}