~ubuntu-branches/ubuntu/edgy/rsnapshot/edgy

« back to all changes in this revision

Viewing changes to utils/rsnapreport.pl

  • Committer: Bazaar Package Importer
  • Author(s): Simon Boulet
  • Date: 2006-06-05 22:03:45 UTC
  • mfrom: (3.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20060605220345-byz0jaecexc3h2m4
Tags: 1.2.9-1
* New upstream release
* Updated Free Software Foundation address in debian/copyright
* Added rsnapshot-diff man page from CVS
* Switched autotools-dev and rsync back to Build-Depends-Indep

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env perl
 
2
# this script prints a pretty report from rsnapshot output
 
3
# in the rsnapshot.conf you must set
 
4
# verbose >= 3
 
5
# and add --stats to rsync_long_args
 
6
# then setup crontab 'rsnapshot daily 2>&1 | rsnapreport.pl | mail -s"SUBJECT" backupadm@adm.com
 
7
# don't forget the 2>&1 or your errors will be lost to stderr
 
8
################################
 
9
## Copyright 2006 William Bear
 
10
## This program is free software; you can redistribute it and/or modify
 
11
## it under the terms of the GNU General Public License as published by
 
12
## the Free Software Foundation; either version 2 of the License, or
 
13
## (at your option) any later version.
 
14
##
 
15
## This program is distributed in the hope that it will be useful,
 
16
## but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
## GNU General Public License for more details.
 
19
##
 
20
## You should have received a copy of the GNU General Public License
 
21
## along with this program; if not, write to the Free Software
 
22
## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
23
################################
 
24
use strict;
 
25
use warnings;
 
26
use English '-no_match_vars';
 
27
 
 
28
my $bufsz = 2;
 
29
my %bkdata=();
 
30
my @errors=();
 
31
 
 
32
sub pretty_print(){
 
33
        my $ofh = select(STDOUT);
 
34
        $FORMAT_NAME="BREPORTBODY";
 
35
        $FORMAT_TOP_NAME="BREPORTHEAD";
 
36
        select($ofh);
 
37
 
 
38
        foreach my $source (keys %bkdata){
 
39
                if($bkdata{$source} =~ /error/i) { print "ERROR $source $bkdata{$source}"; next; }
 
40
                my $files = $bkdata{$source}{'files'};
 
41
                my $filest = $bkdata{$source}{'files_tran'};
 
42
                my $filelistgentime = $bkdata{$source}{'file_list_gen_time'};
 
43
                my $filelistxfertime = $bkdata{$source}{'file_list_trans_time'};
 
44
                my $bytes= $bkdata{$source}{'file_size'}/1000000; # convert to MB
 
45
                my $bytest= $bkdata{$source}{'file_tran_size'}/1000000; # convert to MB
 
46
                $source =~ s/^[^\@]+\@//; # remove username
 
47
format BREPORTHEAD =
 
48
SOURCE                          TOTAL FILES   FILES TRANS      TOTAL MB     MB TRANS   LIST GEN TIME  FILE XFER TIME
 
49
--------------------------------------------------------------------------------------------------------------------
 
50
.
 
51
format BREPORTBODY =
 
52
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<  @>>>>>>>>>>   @>>>>>>>>>> @#########.## @########.##   @>>>>>>>>>>>>  @>>>>>>>>>>>>>
 
53
$source,                        $files,       $filest,    $bytes,       $bytest,       $filelistgentime, $filelistxfertime
 
54
.
 
55
                write STDOUT;
 
56
        }
 
57
}
 
58
 
 
59
sub nextLine($){
 
60
        my($lines) = @_;
 
61
        my $line = <>;
 
62
        push(@$lines,$line);
 
63
        return shift @$lines;
 
64
}
 
65
        
 
66
 
 
67
my @rsnapout = ();
 
68
 
 
69
# load readahead buffer
 
70
for(my $i=0; $i < $bufsz; $i++){
 
71
        $rsnapout[$i] = <>;
 
72
}
 
73
 
 
74
while (my $line = nextLine(\@rsnapout)){
 
75
        if($line =~ /^[\/\w]+\/rsync/) { # find start rsync command line
 
76
                my @rsynccmd=();
 
77
                while($line =~ /\s+\\$/){ # combine wrapped lines
 
78
                        $line =~ s/\\$//g;
 
79
                        $line .= nextLine(\@rsnapout);
 
80
                }
 
81
                push(@rsynccmd,split(/\s+/,$line)); # split into command components
 
82
                my $source = $rsynccmd[-2]; # count backwards: source always second to last
 
83
                #print $source;
 
84
                while($line = nextLine(\@rsnapout)){
 
85
                        # this means we are missing stats info
 
86
                        if($line =~ /^[\/\w]+\/rsync/){ 
 
87
                                unshift(@rsnapout,$line);
 
88
                                push(@errors,"$source NO STATS DATA");
 
89
                                last;  
 
90
                        }
 
91
                        # stat record
 
92
                        if($line =~ /^total size is\s+\d+/){ last; } # this ends the rsync stats record
 
93
                        elsif($line =~ /Number of files:\s+(\d+)/){
 
94
                                $bkdata{$source}{'files'}=$1;
 
95
                        }
 
96
                        elsif($line =~ /Number of files transferred:\s+(\d+)/){
 
97
                                $bkdata{$source}{'files_tran'}=$1;
 
98
                        }
 
99
                        elsif($line =~ /Total file size:\s+(\d+)/){
 
100
                                $bkdata{$source}{'file_size'}=$1;
 
101
                        }
 
102
                        elsif($line =~ /Total transferred file size:\s+(\d+)/){
 
103
                                $bkdata{$source}{'file_tran_size'}=$1;
 
104
                        }
 
105
                        elsif($line =~ /File list generation time:\s+(.+)/){
 
106
                                $bkdata{$source}{'file_list_gen_time'}=$1;
 
107
                        }
 
108
                        elsif($line =~ /File list transfer time:\s+(.+)/){
 
109
                                $bkdata{$source}{'file_list_trans_time'}=$1;
 
110
                        }
 
111
                        elsif($line =~ /ERROR/){ push(@errors,"$source $line"); } # we encountered an rsync error
 
112
                }
 
113
        }
 
114
        elsif($line =~ /ERROR/){ push(@errors,$line); } # we encountered an rsync error
 
115
}
 
116
 
 
117
pretty_print();
 
118
if(scalar @errors > 0){
 
119
        print "\nERRORS\n";
 
120
        print join("\n",@errors);
 
121
        print "\n";
 
122
}