Cacti rrdtool upgrade woes

I wanted to move from my aging home server to a Raspberry Pi for Cacti monitoring. It takes a whole lot less power..

So I do what I always do: move stuff from one server to the other. (I was moving from RRDTool 1.4.3 to 1.4.7 and Cacti 0.8.7g to 0.8.8a)

But while trying to figure out why my graphs were no longer working. I got the following error:

“ERROR: the RRD does not contain an RRA matching the chosen CF”

Turns out something was incompatible between the RRDTool versions.

I wrote a little script for to export and to import the RRDTool files without having to do it manually. (code after the break!)

How do I use this ?
  • Make sure you are root on both servers. (or have sudo powers)
  • take the code below and place it on both your servers /var/lib/cacti/rra dirs (or wherever cacti keeps your rrd files in your distro) as a php file that is executable. (In this case rrdtoolmigration.php)
  • execute the file on the source machine  (it makes a dir and a tar.gz file )
    with the command :
    ./rrdtoolmigration.php export
  • Copy the file migrationdata.tar.gz to the source server’s “/var/lib/cacti/rra” directory with scp
  • Run the command
    (WARNING THIS CAN CAUSE DATA LOSS ON THE TARGET SERVER!!!!!!! MAKE SURE BEFORE EXECUTING THIS!)
    IT OVERWRITES YOUR RRD FILES

    ./rrdtoolmigration.php import

  • Clean up the tar.gz files and directory that it created
  • Possibly update the file permissions..
  • Presto you’re done !
#!/usr/bin/php
<?php
/**
 * Very simple script to export and import your rrdtool files from one architecture to another
 * NO WARANTY!
 * Use this at your own risk. (Please back up first ! )
 * I do not accept responsibility for the usage of this 5 minute slapped together script.
 * 
 * If you found this useful. Drop me a line at 
 * http://blog.johnbakker.name/2013/04/cacti-rrdtool-upgrade-woes
 *  
 */

//make sure the first argument is set
if(count($argv)==1)
{
	die("\n\nusage ./".basename(__FILE__)." export     or  ./".basename(__FILE__)." import\n\n");
}


switch($argv[1])
{
	//exports the rrd files to a bunch of xml files in a tar.gz	
	case "export":
		$dir = opendir(".");
		mkdir("migrationdata");
	
		while($thing = readdir($dir))
		{
			if(strstr($thing,'.rrd'))
			{
			   $cmd = 'rrdtool dump '.$thing.' >migrationdata/'.$thing.'.xml';
			   echo "\n".$cmd."\n\n";
			   echo shell_exec($cmd);
			}
		}
		$cmd = "tar -cvzf migrationdata.tar.gz migrationdata";
		echo shell_exec($cmd);
		echo "\n\n\n Done now copy the migrationdata.tar.gz file to your new location"; 
		break;
		
	//import the xml files back into the target server	
	case "import":
		$cmd = "tar -xvzf migrationdata.tar.gz ";
		echo shell_exec($cmd);
		echo "\n\n";
		$dir = opendir("migrationdata/");
	
		 while($thing = readdir($dir))
	        {
	                if(strstr($thing,'.xml'))
	                {
			   $parts = explode(".",$thing);
			   array_pop($parts);
			   $thing = implode(".",$parts);
	                   $cmd = 'rrdtool restore migrationdata/'.$thing.'.xml '.$thing.' --force-overwrite';
	                   echo "\n".$cmd."\n\n";
	                   echo shell_exec($cmd);
	                }
	        }
		
	break;
}

2 thoughts on “Cacti rrdtool upgrade woes”

  1. Hi John,
    thanks a lot for your script and help.
    I was googling what could be the problem for hours until I found your article and after 3 mins of export/import via your script everything works fine.
    Great job.
    Regards Vratislav.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.