How to backup, transfer, and restore cacti on a new system; and the beer to have when doing it.
Friday, May 14, 2010 at 11:36AM Over about the past month I have started to use cacti to monitor my home network. During this time two things have happened; one, I have started gather a lot of network data, two, Ubuntu 10.04 was released. I initially setup my cacti system on Ubuntu Server 9.10, and now wanted to move my cacti setup to a system running Ubuntu Server 10.04. Installing and setting up cacti on a new install of Ubuntu Server is quite easy, but that would cause me to loose all of my old network traffic data. With a little bit of time, and research, I was able to figure out how to move the data and graphs to the new system.
My old cacti system was an Ubuntu Server 9.10 32-bit and my new system is an Ubuntu Server 10.04 64-bit, both running on a box via Citrix XenServer 5.6 beta. Also, since I am only using the default cacti templates I will not cover how to move any templates from the old system to the new system; this is left to your own, or my future, research.
The first thing that you can do is grab a nice easy drinking beer, I would recommend some of the following;
Victory Prima Pils
Dogfish Head 60 Minute IPA
Or maybe even Stone IPA
Keep in mind, you are looking for a beer that is easy drinking, refreshing, and won't distract you, too much, from your task at hand.
On the old cacti system you will need to do three things;
1) Backup the cacti mysql database
2) Backup the cacti rrd data (graphs)
3) Transfer these items to the new system
To do each of these steps, run the following commands on the old cacti system from your user home directory.
To backup the cacti mysql database;
sudo mysqldump -p cacti > cacti.mysql
To backup the cacti rrd data;
mkdir rra cd rra sudo cp /var/lib/cacti/rra/*.rrd ./ sudo chown YOURUSERNAME:YOURUSERNAME *.rrd for i in *.rrd; do rrdtool dump "$i" "$i".xml; done
Transfer the cacti.mysql file and the rra directory to your user home directory on the new system, my preferred choice is via sftp initiated from the new system.
On the new cacti system you will need to do four things;
1) Install cacti if you already haven't
2) Restore the cacti mysql database
3) Restore the cacti rrd data (graphs)
4) Access your new cacti site
To do each of these steps, run the following commands on the new cacti system from your user home directory.
To install cacti on the new system;
sudo apt-get install cacti
To restore the cacti mysql database;
sudo mysql -p cacti < cacti.mysql
To restore the cacti rrd data;
cd rra for i in *.xml; do rrdtool restore "$i" "$i".rrd; done for i in *.rrd.xml.rrd; do mv "$i" `echo "$i" | sed s/.xml.rrd//g`; done sudo cp *.rrd /var/lib/cacti/rra/ sudo chown www-data:www-data /var/lib/cacti/rra/*.rrd
Access your new cacti site either locally via http://127.0.0.1/cacti if you have a gui installed, or remotely via http://CACTISYSTEMIP/cacti if you are running a headless server. Once you have access you may be asked if this cacti system is a new install or an upgrade, you will want to select the upgrade option. Since this is an upgrade the login information should be the same as on the old cacti system. After you have logged in successfully you should be done and can now go grab another beer to celebrate.
A few good "celebration" beers that I would recommend are;
Arrogant Bastard by Stone Brewing Co. if you are feeling aggressive and "pumped up"
Dogfish Head 90 Minute IPA if you want to relax with something rich and smooth
Trappistes Rochefort 10 if you want something dark, complex, and contemplative
This was put together mostly for my own notes, but I hope that it can also help others.
The NerdyDrunk,
Timothy A. Ingalls
Update:
After trying to follow my own how-to I found that my directions didn't quite work at easily as I was expecting.
To make things easier I ran almost all of the listed commands via a root BASH session. I know a lot of people will say this is a bad idea, but if you are very careful it will make things much easier. You can start a root bash session via;
sudo bash
The only other changes that I made was adding quite a few more chown entries as well as some rm commands, in /home/YOURUSERNAME/rra/, to remove original files as I was using rrdtool on them. For example;
# mysqldump -p cacti > cacti.mysql
# chown YOURUSERNAME:YOURUSERNAME cacti.mysql
# for i in *.rrd; do rrdtool dump "$i" "$i".xml; done
# rm *.rrd
# chown YOURUSERNAME:YOURUSERNAME *.xml
By adding the rm command you will have less files to transfer between machines and you won't accidentally delete or overwrite a .rrd file that you wanted on the new system.
The NerdyDrunk,
Timothy A. Ingalls

Reader Comments (2)
Very useful! Thanks!
ori_the_kid
I am glad that it was helpful, I hope my update makes it easier and quicker for others that may need this information.
The NerdyDrunk,
Timothy A. Ingalls