[rrd-users] Re: [mrtg] converting sparc rrd > x86 rrd

Allan Houston ahouston at blueyonder.co.uk
Thu May 8 15:10:09 MEST 2003


Hi,

----- Original Message -----
From: "Alex van den Bogaerdt" <alex at ergens.op.het.net>
To: <mrtg at list.ee.ethz.ch>; <rrd-users at list.ee.ethz.ch>
Sent: Thursday, May 08, 2003 9:24 AM
Subject: [rrd-users] Re: [mrtg] converting sparc rrd > x86 rrd


> On Thu, May 08, 2003 at 10:53:27AM +1000, Ross Tsolakidis wrote:
>
> > One thing I didn't take into account is the architecture changes, I have
all my SPARC rrd files, but the new accounting box complains about them
being the wrong architecture every time MRTG runs.
> >
> > The new x86 box is working fine, but I would very much like to import
the old SPARC data in, as it has almost a years worth.
> > I have all the old data sitting on my hard drive.
> >
> > Is this possible ?  Keeping in mind I'm not very advanced in using
rrdtool...
>
> I have to assume the RRD files are setup the same.  If so:
>
> - At the same moment create a dump on both platforms.
> - Create a new ascii file, using the recent part of one
>   file and the old part of the other file.
> - restore the newly created file on the desired platform
>
>
> This is something you need to do by hand (using tools of course).
> Get yourself up to speed on the format of rrdtool dump files,
> it isn't that hard.  The date and time per row is specified in
> the xml file, the properties of each RRA are specified and so on.
>
> HTH
> Alex

Hi,

I had some problems with my keyboard, which umm, deleted half my rrds ...
thats the official story anyway ;)
I wrote a quick and dog-ugly script to merge an existing backup from the
week before back in, which might be of some use in this instance. The logic
of searching for "NaN" migh need to be by tweaked a little as I had gaps in
my data, i.e. wasn't concatenating two rrds together. The script also uses
the first xml file as the slightly more trusted source, so if the previous
searches fail, the line from the first file goes in the output.

#!/usr/bin/perl
($file1,$file2,$file3)=@ARGV;

if (! ( ($file1=~/xml/) && ($file2=~/xml/) && ($file3=~/xml/)) ) { die "Use
: $0 <file1.xml> <file2.xml> <outfile.xml>\nFiles must have an extention of
.xml\nExiting.\n"; }

open (FILE1,"$file1") or die "Fatal error - couldn't open input file
$file1..\n";
open (FILE2,"$file2") or die "Fatal error - couldn't open input file
$file2..\n";
open (NEWXML,">$file3") or die "Fatal error - couldn't open output file
$file3..\n";

@file1=<FILE1>;
@file2=<FILE2>;

my $line_count=0;

        foreach $xml (@file1)
        {
                if (!($xml=~/(GMT|BST)/)) {print NEWXML $xml; $line_count++;
next;}

                $xml1=$file1[$line_count];
                $xml2=$file2[$line_count];

                ($date_time,$data)=split /\-\-\>/,$xml1;
                $date_time=~s/\<\!\-\- //g;
                $date_time=~s/\t//g;

                if ( ($xml1=~/NaN/) && (!($xml2=~/NaN/)) )
                {

                        print "[$date_time]\tLine $line_count : Second file
has replacement data - merging..\n";
                        print NEWXML $xml2;
                }
                elsif ( ($xml2=~/NaN/) && (!($xml1=~/NaN/)) )
                {
                        print "[$date_time]\tLine $line_count : First file
has replacement data - merging..\n";
                        print NEWXML $xml1;
                }
                else
                {
                        print NEWXML $xml1;
                }

                $line_count++;

        }

====================================

Then you just use a small bash script like this to batch the updates :

#!/bin/bash

for file in `ls -1 *.rrd`
do
        echo Merging data for $file..
        rrdtool dump $file > file1.xml
        rrdtool dump /path/to/second/file//$file > file2.xml

        /path/to/perl/script/merge_xml.pl file1.xml file2.xml merged.xml
        echo Restoring data from merged file
        mv $file /html/mrtg/router/merge_backup/
        rrdtool restore merged.xml $file
        echo Fixing permissions...
        chown rrduser:rrdgroup $file
        chmod 755 $file
done

Hope it's of some use.

Cheers,
Allan Houston


--
Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-users-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/rrd-users
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the rrd-users mailing list