2
# this script prints a pretty report from rsnapshot output
3
# in the rsnapshot.conf you must set
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.
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.
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
################################
26
use English '-no_match_vars';
33
my $ofh = select(STDOUT);
34
$FORMAT_NAME="BREPORTBODY";
35
$FORMAT_TOP_NAME="BREPORTHEAD";
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
48
SOURCE TOTAL FILES FILES TRANS TOTAL MB MB TRANS LIST GEN TIME FILE XFER TIME
49
--------------------------------------------------------------------------------------------------------------------
52
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>>>>>> @>>>>>>>>>> @#########.## @########.## @>>>>>>>>>>>> @>>>>>>>>>>>>>
53
$source, $files, $filest, $bytes, $bytest, $filelistgentime, $filelistxfertime
69
# load readahead buffer
70
for(my $i=0; $i < $bufsz; $i++){
74
while (my $line = nextLine(\@rsnapout)){
75
if($line =~ /^[\/\w]+\/rsync/) { # find start rsync command line
77
while($line =~ /\s+\\$/){ # combine wrapped lines
79
$line .= nextLine(\@rsnapout);
81
push(@rsynccmd,split(/\s+/,$line)); # split into command components
82
my $source = $rsynccmd[-2]; # count backwards: source always second to last
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");
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;
96
elsif($line =~ /Number of files transferred:\s+(\d+)/){
97
$bkdata{$source}{'files_tran'}=$1;
99
elsif($line =~ /Total file size:\s+(\d+)/){
100
$bkdata{$source}{'file_size'}=$1;
102
elsif($line =~ /Total transferred file size:\s+(\d+)/){
103
$bkdata{$source}{'file_tran_size'}=$1;
105
elsif($line =~ /File list generation time:\s+(.+)/){
106
$bkdata{$source}{'file_list_gen_time'}=$1;
108
elsif($line =~ /File list transfer time:\s+(.+)/){
109
$bkdata{$source}{'file_list_trans_time'}=$1;
111
elsif($line =~ /ERROR/){ push(@errors,"$source $line"); } # we encountered an rsync error
114
elsif($line =~ /ERROR/){ push(@errors,$line); } # we encountered an rsync error
118
if(scalar @errors > 0){
120
print join("\n",@errors);