rdiff-backup-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[rdiff-backup-users] backup-statistics script


From: dean gaudet
Subject: [rdiff-backup-users] backup-statistics script
Date: Sun, 13 Mar 2005 11:59:55 -0800 (PST)

below is a perl script which i run after each backup -- it shows the 
statistics for the most recent session, the average of all sesssions, and 
lists any directories which contain more than 4000000 total bytes of new 
or increment files.  this helps to find which users are causing the most 
rdiff-backup traffic.

invoke with:  backup-statistics /path/to/mirror

(i.e. the path above rdiff-backup-data)

you'll probably want this patch as well -- otherwise filenames with \n
in them can mess up parsing of the file_statistics*gz files.

both of these are now in http://arctic.org/~dean/rdiff-backup/ ... the
patch is included in the "dg3" patch there with several other one-liners.

-dean

diff -ru rdiff-backup-0.13.4.orig/rdiff_backup/statistics.py 
rdiff-backup-0.13.4/rdiff_backup/statistics.py
--- rdiff-backup-0.13.4.orig/rdiff_backup/statistics.py 2004-06-04 
09:59:22.000000000 -0700
+++ rdiff-backup-0.13.4/rdiff_backup/statistics.py      2005-03-13 
11:18:51.000000000 -0800
@@ -20,7 +20,7 @@
 """Generate and process aggregated backup information"""
 
 import re, os, time
-import Globals, Time, increment, log, static
+import Globals, Time, increment, log, static, metadata
 
 class StatsException(Exception): pass
 
@@ -381,6 +381,7 @@
                """Update file stats with given information"""
                if source_rorp: filename = source_rorp.get_indexpath()
                else: filename = dest_rorp.get_indexpath()
+               filename = metadata.quote_path(filename)
 
                size_list = map(cls.get_size, [source_rorp, dest_rorp, inc])
                line = " ".join([filename, str(changed)] + size_list)



#!/usr/bin/perl -w

# an rdiff-backup statistics generating script
#
# supply backup-statstics with a pathname to an rdiff-backup mirror directory
# (i.e. a directory which contains an rdiff-backup subdir) and it will display
# the most recent backup statistics, the average of all backup statistics, and
# any directories which contain a total of more than 4000000 bytes of new files
# or increment files.
#
# Copyright (c) 2005 Dean Gaudet <address@hidden>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.

# $Id: backup-statistics,v 1.4 2005/03/13 19:58:56 dean Exp $

use strict;

my $dir = shift or die "usage: $0 mirror-directory [date_tag]\n";

$dir="$dir/rdiff-backup-data";
-d "$dir" or die "$0: $dir is not a directory\n";

my $tag = shift;
if (!defined($tag)) {
        my @current = sort <$dir/current_mirror.*.data>;
        $tag = $current[$#current];
        $tag =~ s#.*/current_mirror.(.*).data#$1#;
}
print "Statistics for $dir $tag:\n";

print "\nSession statistics:\n";
my $sfile = "$dir/session_statistics.$tag.data";
open(SFILE, "<$sfile") or die "$0: unable to read $sfile: $!\n";
print <SFILE>;
close(SFILE);


print "\nAverage statistics:\n";
system("rdiff-backup --calculate-average $dir/session_statistics.*");


my $limit = 4;
print "\nDirectory statistics (total of new or inc filesizes over 
${limit}MB):\n";
my $fsfile = "$dir/file_statistics.$tag.data.gz";
-r $fsfile or die "$0: unable to read $fsfile: $!\n";
open(FS, "zcat '$fsfile' |") or die "unable to fork zcat $fsfile: $!\n";

my $line = <FS>;
chomp($line);
$line eq '# Format of each line in file statistics file:' or die "$0: 
unexpected first line\n";
$line = <FS>;
chomp($line);
$line eq '# Filename Changed SourceSize MirrorSize IncrementSize' or die "$0: 
unexpected second line\n";

my $warnings = 0;
my %newfile;
my %incfile;

while (<FS>) {
        chomp;
        my ($filename, $changed, $ssize, $msize, $isize) = m#^(.*) (\S+) (\S+) 
(\S+) (\S+)$#;
        if (!defined($isize)) {
                warn "unable to parse: $_\n";
                ++$warnings;
                if ($warnings == 100) {
                        die "too many warnings\n";
                }
                next;
        }

        my $newsize = ($ssize ne 'NA' and $msize eq 'NA') ? $ssize : 0;
        my $incsize = ($isize ne 'NA') ? $isize : 0;
        my $parent = $filename;
        while ($parent =~ s#(.*)/[^/]+#$1#) {
                if (!defined($newfile{$parent})) {
                        $newfile{$parent} = 0;
                        $incfile{$parent} = 0;
                }
                $newfile{$parent} += $newsize;
                $incfile{$parent} += $incsize;
        }
}

my $key;
foreach $key (sort { $newfile{$b} <=> $newfile{$a} } keys %newfile) {
        last if ($newfile{$key} < $limit*1000000);
        printf "new %12s %s\n", $newfile{$key}, $key;
}

foreach $key (sort { $incfile{$b} <=> $incfile{$a} } keys %incfile) {
        last if ($incfile{$key} < $limit*1000000);
        printf "inc %12s %s\n", $incfile{$key}, $key;
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]