first try at generating Excel report
authordpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Fri, 19 Aug 2005 21:52:43 +0000 (21:52 +0000)
committerdpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Fri, 19 Aug 2005 21:52:43 +0000 (21:52 +0000)
git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/BackupPC/trunk@41 8392b6e1-25fa-0310-8288-cc32f8e212ea

bin/BackupPC_xls_report [new file with mode: 0755]
configure.pl

diff --git a/bin/BackupPC_xls_report b/bin/BackupPC_xls_report
new file mode 100755 (executable)
index 0000000..f7c10ab
--- /dev/null
@@ -0,0 +1,113 @@
+#!/usr/local/bin/perl
+
+use strict;
+use lib "__INSTALLDIR__/lib";
+use BackupPC::Lib;
+use BackupPC::View;
+use Data::Dumper;
+use Spreadsheet::WriteExcel;
+use POSIX qw/strftime/;
+
+my $xls_file = '/tmp/report.xls';
+
+my $workbook  = Spreadsheet::WriteExcel->new($xls_file) || die "can't write to $xls_file: $!";
+
+my @cols = qw(
+type
+num
+startTime
+endTime
+=D##-C##,duration
+level
+noFill
+fillFromNum
+mangle
+
+nFiles
+nFilesNew
+nFilesExist
+
+xferErrs
+xferMethod
+xferBadShare
+xferBadFile
+tarErrs
+
+size
+sizeNew
+sizeExist
+
+compress
+sizeNewComp
+=V##/S##,sizeNewRatio
+sizeExistComp
+=X##/T##,sizeExistRatio
+);
+
+my $date_format = $workbook->add_format(num_format => 'yyyy-mm-dd hh:mm:ss');
+my $duration_format = $workbook->add_format(num_format => 'hh:mm:ss');
+my $header_format = $workbook->add_format(color => 'gray');
+my $pcnt_format = $workbook->add_format(num_format => '0.0%');
+
+my $formats = {
+       duration => $duration_format,
+       sizeNewRatio => $pcnt_format,
+       sizeExistRatio => $pcnt_format,
+};
+
+my $bpc = BackupPC::Lib->new || die;
+my %Conf = $bpc->Conf();
+my $TopDir = $bpc->TopDir();
+
+my $hosts = $bpc->HostInfoRead();
+
+foreach my $host_key (keys %{$hosts}) {
+
+       my $hostname = $hosts->{$host_key}->{'host'} || die "can't find host for $host_key";
+
+       print $hostname, " ";
+
+       my $worksheet = $workbook->add_worksheet($hostname);
+
+       # get backups for a host
+       my @backups = $bpc->BackupInfoRead($hostname);
+       print scalar @backups, " increments\n";
+
+       my $row = 0;
+       my $i = 0;
+
+       foreach my $c (@cols) {
+               if ($c =~ m/^=.*,(.+)/) {
+                       $worksheet->write($row, $i++, $1, $header_format);
+               } else {
+                       $worksheet->write($row, $i++, $c, $header_format);
+               }
+       }
+       $row++;
+
+       foreach my $backup (@backups) {
+               for (my $i = 0; $i <= $#cols; $i++) {
+                       my $col = $cols[$i];
+                       if ($col =~ m/Time/) {
+                               $worksheet->write_date_time($row, $i, 
+                                       strftime("%Y-%m-%dT%H:%M:%S", localtime( $backup->{ $cols[$i] }) ),
+                                       $date_format
+                               );
+                       } elsif ($col =~ m/(=[^,]+),*(.*)/) {
+                               my ($f,$n) = ($1,$2);
+                               $f =~ s/##/($row+1)/ge;
+                               $worksheet->write($row, $i, $f, $formats->{$n});
+                       } else {
+                               $worksheet->write($row, $i, $backup->{ $cols[$i] });
+                       }
+               }
+               $row++;
+       }
+
+
+}
+
+$workbook->close();
+
+print "Created $xls_file\n";
+
index b119401..5d41a72 100755 (executable)
@@ -487,7 +487,8 @@ printf("Installing binaries in $DestDir$Conf{InstallDir}/bin\n");
 foreach my $prog ( qw(BackupPC BackupPC_dump BackupPC_link BackupPC_nightly
         BackupPC_sendEmail BackupPC_tarCreate BackupPC_trashClean
         BackupPC_tarExtract BackupPC_compressPool BackupPC_zcat
-        BackupPC_archive BackupPC_archiveHost BackupPC_updatedb
+        BackupPC_archive BackupPC_archiveHost
+       BackupPC_updatedb BackupPC_xls_report
         BackupPC_restore BackupPC_serverMesg BackupPC_zipCreate ) ) {
     InstallFile("bin/$prog", "$DestDir$Conf{InstallDir}/bin/$prog", 0555);
 }