/[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 43 - (show annotations)
Fri Aug 19 22:12:56 2005 UTC (18 years, 9 months ago) by dpavlin
File size: 2417 byte(s)
fix size format

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 my $size_format = $workbook->add_format(num_format => '#0');
52
53 my $formats = {
54 duration => $duration_format,
55 sizeNewRatio => $pcnt_format,
56 sizeExistRatio => $pcnt_format,
57 size => $size_format,
58 sizeNew => $size_format,
59 sizeExist => $size_format,
60 sizeNewComp => $size_format,
61 sizeExistComp => $size_format,
62 };
63
64 my $bpc = BackupPC::Lib->new || die;
65 my %Conf = $bpc->Conf();
66 my $TopDir = $bpc->TopDir();
67
68 my $hosts = $bpc->HostInfoRead();
69
70 foreach my $host_key (keys %{$hosts}) {
71
72 my $hostname = $hosts->{$host_key}->{'host'} || die "can't find host for $host_key";
73
74 print $hostname, " ";
75
76 my $worksheet = $workbook->add_worksheet($hostname);
77
78 # get backups for a host
79 my @backups = $bpc->BackupInfoRead($hostname);
80 print scalar @backups, " increments\n";
81
82 my $row = 0;
83 my $i = 0;
84
85 foreach my $c (@cols) {
86 if ($c =~ m/^=.*,(.+)/) {
87 $worksheet->write($row, $i++, $1, $header_format);
88 } else {
89 $worksheet->write($row, $i++, $c, $header_format);
90 }
91 }
92 $row++;
93
94 foreach my $backup (@backups) {
95 for (my $i = 0; $i <= $#cols; $i++) {
96 my $col = $cols[$i];
97 if ($col =~ m/Time/) {
98 $worksheet->write_date_time($row, $i,
99 strftime("%Y-%m-%dT%H:%M:%S", localtime( $backup->{ $cols[$i] }) ),
100 $date_format
101 );
102 } elsif ($col =~ m/(=[^,]+),*(.*)/) {
103 my ($f,$n) = ($1,$2);
104 $f =~ s/##/($row+1)/ge;
105 $worksheet->write($row, $i, $f, $formats->{$n});
106 } else {
107 $worksheet->write($row, $i, $backup->{$col}, $formats->{$col});
108 }
109 }
110 $row++;
111 }
112
113
114 }
115
116 $workbook->close();
117
118 print "Created $xls_file\n";
119

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26