M
Matt Williamson
The purpose of this script is to quickly get a status on all of my nightly
backups. It's working for everything but the .xml backup files. There are
multiple .xml files created each night for the various processes that occur,
the actual backup log is only one of them. I've determined that the .xml
backup log files that I want are all encoded utf16le and the others are
utf8. I only want to read the utf16le .xml files and print the server name
and filename for just the latest of those but I can't figure out the best
way to do it. Also, if you have any suggestions on the script in general,
please feel free to comment. I'm new at this, so any advice from experienced
coders is welcome and appreciated.
use strict;
use warnings;
my @content;
my @header;
my %belogdirs = (
"\\\\Server1" => "\\d\$\\Backup Exec\\data\\bex*.txt",
\\\\Server2 => "\\c\$\\Program Files\\Seagate Software\\Backup
Exec\\Nt\\Data\\bex*.txt",
\\\\Server3 => "\\c\$\\Program Files\\Veritas\\Backup
Exec\\Nt\\Data\\bex*.txt",
\\\\Server4 => "\\c\$\\Program Files\\Veritas\\Backup
Exec\\Nt\\Data\\bex*.txt",
\\\\Server5 => "\\c\$\\Program Files\\Veritas\\Backup
Exec\\Nt\\Data\\bex*.txt",
\\\\Server6 => "\\c\$\\Program Files\\Veritas\\Backup
Exec\\Nt\\Data\\bex*.xml"
);
open FILE, ">C:\\Backup Tape Log.txt";
foreach my $server (keys %belogdirs) {
my $fullpath = $server.$belogdirs{$server};
my @files = `dir "$fullpath" /OD /B`;
foreach my $file (reverse @files) {
$fullpath =~ s/bex\*\.xml|bex\*\.txt/$file/i;
chomp $fullpath;
open F, $fullpath or die "can't open $file: $!\n";
read F, my $buffer, 2;
@header = unpack "h*", $buffer;
close F;
if ($header[0] =~ /ffef/i) { #handle the utf16 .xml files
open F, "<:encoding(utf16le)", $fullpath or
die "can't open $file: $!\n";
@content = <F>;
close F;
}
elsif ($header[0] =~ /efff/i) { # just in case?
open F, "<:encoding(utf16be)", $fullpath or
die "can't open $file: $!\n";
@content = <F>;
close F;
}
else { # handle the .txt files
open F, $fullpath or
die "can't open $file: $!\n";
@content = <F>;
close F;
}
# $server =~ s/\\\\/Server: /;
# print FILE $server, "\n";
# print FILE "Log File: ",$fullpath,"\n";
foreach my $line (@content){
if ($line =~ /(job (?:started|ended|completion status)):\s*(.*?)\s*$/i) {
my ($job_type, $status) = ($1, $2);
print FILE "$job_type: $status\n";
}
}
print FILE "\n";
last;
}
}
close FILE;
exec("notepad C:\\Backup Tape Log.txt");
TIA
Matt
backups. It's working for everything but the .xml backup files. There are
multiple .xml files created each night for the various processes that occur,
the actual backup log is only one of them. I've determined that the .xml
backup log files that I want are all encoded utf16le and the others are
utf8. I only want to read the utf16le .xml files and print the server name
and filename for just the latest of those but I can't figure out the best
way to do it. Also, if you have any suggestions on the script in general,
please feel free to comment. I'm new at this, so any advice from experienced
coders is welcome and appreciated.
use strict;
use warnings;
my @content;
my @header;
my %belogdirs = (
"\\\\Server1" => "\\d\$\\Backup Exec\\data\\bex*.txt",
\\\\Server2 => "\\c\$\\Program Files\\Seagate Software\\Backup
Exec\\Nt\\Data\\bex*.txt",
\\\\Server3 => "\\c\$\\Program Files\\Veritas\\Backup
Exec\\Nt\\Data\\bex*.txt",
\\\\Server4 => "\\c\$\\Program Files\\Veritas\\Backup
Exec\\Nt\\Data\\bex*.txt",
\\\\Server5 => "\\c\$\\Program Files\\Veritas\\Backup
Exec\\Nt\\Data\\bex*.txt",
\\\\Server6 => "\\c\$\\Program Files\\Veritas\\Backup
Exec\\Nt\\Data\\bex*.xml"
);
open FILE, ">C:\\Backup Tape Log.txt";
foreach my $server (keys %belogdirs) {
my $fullpath = $server.$belogdirs{$server};
my @files = `dir "$fullpath" /OD /B`;
foreach my $file (reverse @files) {
$fullpath =~ s/bex\*\.xml|bex\*\.txt/$file/i;
chomp $fullpath;
open F, $fullpath or die "can't open $file: $!\n";
read F, my $buffer, 2;
@header = unpack "h*", $buffer;
close F;
if ($header[0] =~ /ffef/i) { #handle the utf16 .xml files
open F, "<:encoding(utf16le)", $fullpath or
die "can't open $file: $!\n";
@content = <F>;
close F;
}
elsif ($header[0] =~ /efff/i) { # just in case?
open F, "<:encoding(utf16be)", $fullpath or
die "can't open $file: $!\n";
@content = <F>;
close F;
}
else { # handle the .txt files
open F, $fullpath or
die "can't open $file: $!\n";
@content = <F>;
close F;
}
# $server =~ s/\\\\/Server: /;
# print FILE $server, "\n";
# print FILE "Log File: ",$fullpath,"\n";
foreach my $line (@content){
if ($line =~ /(job (?:started|ended|completion status)):\s*(.*?)\s*$/i) {
my ($job_type, $status) = ($1, $2);
print FILE "$job_type: $status\n";
}
}
print FILE "\n";
last;
}
}
close FILE;
exec("notepad C:\\Backup Tape Log.txt");
TIA
Matt