How To: Migrate Cacti to another host

I’ve been using cacti for network stat collection for years. In that time I’ve had to move cacti from one linux server to another. Keeping all the historical rrd data was of top priority. I just did another migration this morning. My notes were the key. I’m going to share them with you here.

A few things are assumed:

To start a quick outline of what needs to be done:

  • install cacti on the new machine and verify that it is working!
  • stop the poller on both cacti installs
  • copy the old database to the new one
  • copy your scripts and resources folders from the old to new (if you have any custom scripts)
  • convert all old rrd files to xml files
  • move/copy the xml files to the new cacti
  • convert the xml files back to rrd format
  • turn on the poller and test!

Why do the old rrd files need to be turned into xml files? rrdtool doesn’t like rrd files made on different machines. Even if they are identical machines/OSes. rrdtool is kind enough to allow you to export/import using the xml files to get around this.

General Steps

Make note of which cacti machine each command needs to run on! Context is very important!

After installing the new cacti, make sure it’s working.

Next get samba setup on the old cacti machine and share the whole cacti folder. Security shouldn’t be an issue so you can share without the need for credentials.

Mount the rra folder on the new cacti machine, I used this command:

mount -t cifs //kny_netmon/root/var/www/cacti/rra /mnt/oldcacti

Copy over your scripts and resources folders from the old cacti to the new cacti. This should be done from the new cacti machine.

You can do the sql database export several ways. I chose to export the database on the old machine. I used this command:

mysqldump --user=root --password=password cacti > /var/www/cacti/newcacti.sql

If you want to do the sql export from the new machine you can do it like this (the resulting sql file will still be on the old cacti machine though):

ssh root@kny_netmon mysqldump --user=root --password=password cacti > /var/www/cacti/newcacti.sql

Next, import the database to the new cacti database, remember you’re on the new cacti machine for this command.

mysql cacti < /mnt/oldcacti/newcacti.sql

On the old cacti machine, do the xml export. Run this from the rra folder!:

for i in *.rrd; do rrdtool dump $i > $i.xml; done

On the new cacti machine, copy the xml files to the rra folder:

 rsync -avz --exclude=*.rrd /mnt/oldcacti/ /var/www/cacti/rra

We don’t want the old rrd files so they’re excluded.

When the copy is done, on the new cacti convert the xml files back to rrd files:

for i in /var/www/cacti/rra/*.xml; do A=`echo $i|sed 's/.xml//'`; rrdtool restore -f $i $A; done

Remove the old xml files from the new and old cacti:

rm /var/www/cacti/rra/*.xml -f

Now here’s the wacky part. In all my years I’ve setup cacti on Windows, CentOS, Debian, Ubuntu and MacOS. Permissions are ALWAYS an issue in the rra folder. I haven’t discovered the proper permissions so I just chmod them 777 and it seems to work. So unless you know the proper permissions just chmod them 777:

chmod 777 -R /var/www/cacti/*

 

I do the whole folder just in case….I know it’s BAD security but all my cacti installs are on private networks.

Start up the poller on the new cacti and start watching your log files and graphs. They should work!

My only issue on my last migration was that my snmp host only respond to certain IP addresses so I had to add the new cacti machines address. Otherwise it picked up where it left off.

Notes

For the sake of this “tutorial” I didn’t present any scripts.

when I do this “live” I’m able to literally get all this done in less than 5 minutes. Know why that’s important? Of course you do! The poller runs every 5 minutes.

If you can start at the end of the old cacti pollers cycle you can be ready for the next cycle on the new cacti. Pretty neat!

Don’t be afraid to test the procedure. All the copying/updating on the new cacti overwrites its settings. Each time you run this procedure you’re picking up the new/updated data from the old cacti.

You *could* leave the poller running on the old cacti if you want. I did, just making sure that the xml export was done in less than 5 minutes. I have about 900 rrd files so it’s fairly quick.

 

Good luck!

 

 

 

Author: Helicopter Jeff

I'm a vinyl decal cutting and designing, Astrophotography and general photography capturing, RC helicopter/quad copter pilot, Arduino and Raspberry Pi hardware/software developer, network, scripting and troubleshooting ninja living in the metro NY area. I am passionate about my hobbies so much I do them for a living. There's nothing better than getting paid to do what you love.