/[BackupPC]/trunk/bin/BackupPC_xls_report
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/bin/BackupPC_xls_report

Parent Directory Parent Directory | Revision Log Revision Log


Revision 41 - (show annotations)
Fri Aug 19 21:52:43 2005 UTC (18 years, 8 months ago) by dpavlin
File size: 2206 byte(s)
first try at generating Excel report

1 #!/usr/local/bin/perl
2
3 use strict;
4 use lib "__INSTALLDIR__/lib";
5 use BackupPC::Lib;
6 use BackupPC::View;
7 use Data::Dumper;
8 use Spreadsheet::WriteExcel;
9 use POSIX qw/strftime/;
10
11 my $xls_file = '/tmp/report.xls';
12
13 my $workbook = Spreadsheet::WriteExcel->new($xls_file) || die "can't write to $xls_file: $!";
14
15 my @cols = qw(
16 type
17 num
18 startTime
19 endTime
20 =D##-C##,duration
21 level
22 noFill
23 fillFromNum
24 mangle
25
26 nFiles
27 nFilesNew
28 nFilesExist
29
30 xferErrs
31 xferMethod
32 xferBadShare
33 xferBadFile
34 tarErrs
35
36 size
37 sizeNew
38 sizeExist
39
40 compress
41 sizeNewComp
42 =V##/S##,sizeNewRatio
43 sizeExistComp
44 =X##/T##,sizeExistRatio
45 );
46
47 my $date_format = $workbook->add_format(num_format => 'yyyy-mm-dd hh:mm:ss');
48 my $duration_format = $workbook->add_format(num_format => 'hh:mm:ss');
49 my $header_format = $workbook->add_format(color => 'gray');
50 my $pcnt_format = $workbook->add_format(num_format => '0.0%');
51
52 my $formats = {
53 duration => $duration_format,
54 sizeNewRatio => $pcnt_format,
55 sizeExistRatio => $pcnt_format,
56 };
57
58 my $bpc = BackupPC::Lib->new || die;
59 my %Conf = $bpc->Conf();
60 my $TopDir = $bpc->TopDir();
61
62 my $hosts = $bpc->HostInfoRead();
63
64 foreach my $host_key (keys %{$hosts}) {
65
66 my $hostname = $hosts->{$host_key}->{'host'} || die "can't find host for $host_key";
67
68 print $hostname, " ";
69
70 my $worksheet = $workbook->add_worksheet($hostname);
71
72 # get backups for a host
73 my @backups = $bpc->BackupInfoRead($hostname);
74 print scalar @backups, " increments\n";
75
76 my $row = 0;
77 my $i = 0;
78
79 foreach my $c (@cols) {
80 if ($c =~ m/^=.*,(.+)/) {
81 $worksheet->write($row, $i++, $1, $header_format);
82 } else {
83 $worksheet->write($row, $i++, $c, $header_format);
84 }
85 }
86 $row++;
87
88 foreach my $backup (@backups) {
89 for (my $i = 0; $i <= $#cols; $i++) {
90 my $col = $cols[$i];
91 if ($col =~ m/Time/) {
92 $worksheet->write_date_time($row, $i,
93 strftime("%Y-%m-%dT%H:%M:%S", localtime( $backup->{ $cols[$i] }) ),
94 $date_format
95 );
96 } elsif ($col =~ m/(=[^,]+),*(.*)/) {
97 my ($f,$n) = ($1,$2);
98 $f =~ s/##/($row+1)/ge;
99 $worksheet->write($row, $i, $f, $formats->{$n});
100 } else {
101 $worksheet->write($row, $i, $backup->{ $cols[$i] });
102 }
103 }
104 $row++;
105 }
106
107
108 }
109
110 $workbook->close();
111
112 print "Created $xls_file\n";
113

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26