{"id":2485,"date":"2016-08-08T00:00:27","date_gmt":"2016-08-08T07:00:27","guid":{"rendered":"http:\/\/192.168.3.4\/?p=2485"},"modified":"2018-01-09T06:50:18","modified_gmt":"2018-01-09T14:50:18","slug":"cacti-sandbox","status":"publish","type":"post","link":"https:\/\/www.cloudacm.com\/?p=2485","title":{"rendered":"Cacti Sandbox"},"content":{"rendered":"<p><strong>Introduction<\/strong><\/p>\n<p>Having a sandbox is great way to test your disaster recovery methods.\u00a0 I&#8217;ll step through a process that makes a backup of the Cacti data.\u00a0 Then we can use that backup file to restore from as needed.<\/p>\n<p>There are some prerequirements to the steps I&#8217;ll be using.\u00a0 These are LAMP, phpMyAdmin, Webmin, Cacti, and a ssh client.<\/p>\n<p>Do keep in mind that any plugins or templates that are not standard are not included in this backup.\u00a0 This simply gives you a way to view your Cacti graphs on a sandbox.<\/p>\n<p>With that said, lets begin.<\/p>\n<p><strong>Backup the Source Cacti Data<\/strong><\/p>\n<p>First we&#8217;ll backup the Cacti data on the source.<\/p>\n<p>I like to get all the tools running before starting.\u00a0 Open up a ssh session to the source.\u00a0 Also open up the source system&#8217;s Webmin, Cacti, and phpMyAdmin web pages.<\/p>\n<p>Create a folder on the source to back everything up to with this command.\u00a0 It creates a folder with a time stamp.<\/p>\n<pre># mkdir \/home\/local\/cacti-temp-$(date +%Y%m%d)<\/pre>\n<p>Disable CRON Cacti Poller on the source Cacti Server, I do this from Webmin.\u00a0 The rest of these steps will be done with a terminal session on the source Cacti Server.<\/p>\n<p>Next, I&#8217;ll backup the cacti database on the source Cacti Server with this command.<\/p>\n<pre># mysqldump -u root -p cacti &gt; \/home\/local\/cacti-temp-$(date +%Y%m%d)\/cactidump.sql<\/pre>\n<p>Finally, I&#8217;ll convert the RRD files to XML on the source Cacti Server with following commands under root using su:<\/p>\n<pre># cd \/var\/lib\/cacti\/rra\r\n# for i in `find -name \"*.rrd\"`; do rrdtool dump $i &gt; \/home\/local\/cacti-temp-$(date +%Y%m%d)\/$i.xml; done<\/pre>\n<p>Now the CRON Cacti Poller can be restarted, we&#8217;ve got our backup done.\u00a0 Next, I&#8217;ll compress the XML files with these commands:<\/p>\n<pre># cd \/home\/local\/cacti-temp-$(date +%Y%m%d)\r\n# tar cvfz cacti-backup_$(date +%Y%m%d).tar.gz *<\/pre>\n<p>One final thing before uploading everything is changing the rights to the backup folder and files so our ordinary user can access them.<\/p>\n<pre># chown local:local \/home\/local\/cacti-temp-$(date +%Y%m%d)\r\n# chown local:local \/home\/local\/cacti-temp-$(date +%Y%m%d)\/*<\/pre>\n<p>Then I&#8217;ll copy the backup files to the target Cacti Server with command using my user account.<\/p>\n<pre># scp cacti-backup_$(date +%Y%m%d).tar.gz user@target_cacti_server:\/home\/local\r\n- or -\r\nrsync -avz -e \"ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=\/dev\/null\" --progress cacti-backup_$(date +%Y%m%d).tar.gz user@target_cacti_server:\/home\/local<\/pre>\n<p>It&#8217;s also a good idea to do house cleaning when you&#8217;re done.\u00a0 These commands should suffice.<\/p>\n<pre># rm \/home\/local\/cacti-temp-$(date +%Y%m%d)\/*\r\n# rmdir \/home\/local\/cacti-temp-$(date +%Y%m%d)<\/pre>\n<p><strong>Backup the Target Cacti Data<\/strong><\/p>\n<p>It&#8217;s good practice to backup the Cacti on the target also.\u00a0 You can revert back to the initial install should the need arise.<\/p>\n<p>Here is the commands all in a row, much easier if you just run them as su, just saying.\u00a0 Stop the CRON job for Cacti first, once these are done, keep it stopped.<\/p>\n<pre># mkdir \/home\/local\/cacti-temp-$(date +%Y%m%d)\r\n# mysqldump -u root -p cacti &gt; \/home\/local\/cacti-temp-$(date +%Y%m%d)\/cactidump.sql\r\n\r\n# cd \/var\/lib\/cacti\/rra\r\n# for i in `find -name \"*.rrd\"`; do rrdtool dump $i &gt; \/home\/local\/cacti-temp-$(date +%Y%m%d)\/$i.xml; done\r\n\r\n# cd \/home\/local\/cacti-temp-$(date +%Y%m%d)\r\n# tar cvfz cacti-backup_$(date +%Y%m%d).tar.gz *\r\n\r\n# chown local:local \/home\/local\/cacti-temp-$(date +%Y%m%d)\r\n# chown local:local \/home\/local\/cacti-temp-$(date +%Y%m%d)\/*<\/pre>\n<p><strong>Restore the Cacti Data on the Target<\/strong><\/p>\n<p>First we&#8217;ll need to decompress the source data on the target.\u00a0 Issue this command.<\/p>\n<pre># mkdir \/home\/local\/cacti-restore-$(date +%Y%m%d)\r\n# cp\u00a0 \/home\/local\/cacti-backup_$(date +%Y%m%d).tar.gz \/home\/local\/cacti-restore-$(date +%Y%m%d)\r\n# rm \/home\/local\/cacti-backup_$(date +%Y%m%d).tar.gz\r\n# cd \/home\/local\/cacti-restore-$(date +%Y%m%d)\r\n# tar zxvf cacti-backup_$(date +%Y%m%d).tar.gz<\/pre>\n<p>Next, we&#8217;ll need to clear out the existing data on our target to make way for the import data from our source.\u00a0 Run these commands as su to purge the RRD files and tables from the CACTI database.<\/p>\n<pre># cd \/var\/lib\/cacti\/rra\r\n# rm \/var\/lib\/cacti\/rra\/*<\/pre>\n<p>Now we want to restore our XML files to RRD files on our target.\u00a0 Be sure to include setting the permissions.<\/p>\n<pre># cp \/home\/local\/cacti-restore-$(date +%Y%m%d)\/*.xml \/var\/lib\/cacti\/rra\r\n# for i in `find -name \"*.xml\"`; do rrdtool restore $i `echo $i |sed s\/.xml\/\/g`; done\r\n# rm \/var\/lib\/cacti\/rra\/*.xml\r\n# chown www-data:www-data \/var\/lib\/cacti\/rra\/*.rrd<\/pre>\n<p>You can exit out of su.\u00a0 Now we&#8217;ll drop our CACTI database and create it again.<\/p>\n<pre># mysql -u root -p\r\nEnter password....\r\n&gt; drop database cacti;\r\n&gt; create database cacti;\r\n&gt; exit<\/pre>\n<p>This is when we&#8217;re ready to import our CACTI data back into MySQL.<\/p>\n<pre># mysql -u root -p cacti &lt; \/home\/local\/cacti-restore-$(date +%Y%m%d)\/cactidump.sql<\/pre>\n<p>That my friends should get you operational.\u00a0 Go ahead to the Cacti web page on your target sandbox machine, you should see all of your data.<\/p>\n<p><strong>Credit to those that helped with the details of this post<\/strong><\/p>\n<p><a href=\"http:\/\/xmodulo.com\/migrate-cacti-server.html\">http:\/\/xmodulo.com\/migrate-cacti-server.html<\/a> &#8211; May 9th, 2016<\/p>\n<p>PackT publishing book titled \u201cCacti 0.8 \u2013 Beginnner&#8217;s Guide\u201d from Thomas Urban.<br \/>\n<a href=\"https:\/\/www.packtpub.com\/networking-and-servers\/cacti-08-beginners-guide\">https:\/\/www.packtpub.com\/networking-and-servers\/cacti-08-beginners-guide<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Having a sandbox is great way to test your disaster recovery methods.\u00a0 I&#8217;ll step through a process that makes a backup of the Cacti data.\u00a0 Then we can use that backup file to restore from as needed. There are some prerequirements to the steps I&#8217;ll be using.\u00a0 These are LAMP, phpMyAdmin, Webmin, Cacti, and a ssh client. Do keep in mind that any plugins or templates that are not standard are not included in this backup.\u00a0 This simply gives&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.cloudacm.com\/?p=2485\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,3],"tags":[],"class_list":["post-2485","post","type-post","status-publish","format-standard","hentry","category-raspberry-pi","category-rd"],"_links":{"self":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/2485","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2485"}],"version-history":[{"count":5,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/2485\/revisions"}],"predecessor-version":[{"id":2487,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/2485\/revisions\/2487"}],"wp:attachment":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2485"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2485"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2485"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}