hpw2007v wrote:
> 1. Convert all rrd databases to xml files and move them to the new 64bits 
> server http://foonet.be/2009/03/11/rrdtool-32bit-to-64bit/

I wrote this two scripts for our RRD 32bit -> 64 bit migration. They are pretty 
hacked together and lack thinks like option parsing. But they did the job for 
me and should help as a reference.

zenrrddump.py

Code:
#! /usr/bin/env python
import os
import tarfile
from fnmatch import fnmatch

zenperfdir = "/usr/local/zenoss/perf"
rrdtool  = "/usr/local/zenoss/bin/rrdtool"
tarfilename = "rrd_xml_dump.tgz"

for dirpath,dirnames,filenames in os.walk(zenperfdir):

        created_tarfile = False
        
        for filename in filenames:
                if fnmatch(filename,"*.rrd"):
                        if not created_tarfile:
                                print ("Processing %s"%dirpath) 
                                tarfilepath = os.path.join(dirpath,tarfilename)
                                os.chdir(dirpath)
                                tar = tarfile.open(tarfilepath,'w|gz')
                                created_tarfile = True
                                
                        rrdfile = filename
                        xmlfile = rrdfile.replace(".rrd",".xml")
                        rrdcommand = "rrdtool dump %r > %r"%(rrdfile,xmlfile)
                        os.system (rrdcommand)
                        tar.add(xmlfile)                
                        os.remove(xmlfile)
                        
        if created_tarfile:
                tar.close()




zenrrdrestore.py

Code:

#! /usr/bin/env python
import os
import sys
import tarfile
from fnmatch import fnmatch

zenperfdir = "/usr/local/zenoss/perf"
rrdtool  = "/usr/local/zenoss/bin/rrdtool"
tarfilename = "rrd_xmldump.tgz"

for dirpath,dirnames,filenames in os.walk(zenperfdir):
        os.chdir(dirpath)
        for filename in filenames:
                if fnmatch(filename,tarfilename):
                        tarfilepath = os.path.join(dirpath,tarfilename)
                        print ("Restoring %s"%dirpath)
                        tar = tarfile.open(tarfilepath,'r|gz')

                        for tarinfo in tar:
                                tar.extract(tarinfo)
                                xmlfile = os.path.join(dirpath,tarinfo.name)
                                rrdfile = xmlfile.replace(".xml",".rrd")
                                try: 
                                        os.remove(rrdfile)
                                except OSError:
                                        pass
                                
                                rrdcommand = "rrdtool restore %r 
%r"%(xmlfile,rrdfile)
                                os.system (rrdcommand)
                                os.remove(xmlfile)
                                        
                        tar.close()



The way these two scripts  work is like this: Zenrrddump does iterate through 
all your RRD graph directories, converts every RRD graph into an RDD-XML files 
and packs every RRD-XML files within a directory into a tgz file called 
rrd_xml_dump.tgz. If you use zenbackup all the rrd_xml_dump.tgz files are 
automatically backed up along with your 32bit RRD files into your zenoss backup 
file.

On your new 64bit box you can use zenrestore to restore your data and then use 
zenrrdrestore to convert the rrd_xml_dump.tgz file back into RRD files that fit 
your new architecture.  Be a bit carefull with running zenrrdrestore, because 
it does overwrite your original RRD files and replaces them with the values 
saved in the XML dump.




-------------------- m2f --------------------

Read this topic online here:
http://forums.zenoss.com/viewtopic.php?p=34610#34610

-------------------- m2f --------------------



_______________________________________________
zenoss-users mailing list
[email protected]
http://lists.zenoss.org/mailman/listinfo/zenoss-users

Reply via email to