1

I have an older cacti database with critical data I am trying to recover. The old database has many less fields than the new current stable. Doing a manual import produces wild errors. How do you import and older Cacti db into current stable?

mysql> use cacti;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

mysql> show tables;
+---------------------------+
| Tables_in_cacti           |
+---------------------------+
| cdef                      |
| cdef_items                |
| colors                    |
| data_input                |
| data_input_data           |
| data_input_fields         |
| data_local                |
| data_template             |
| data_template_data        |
| data_template_data_rra    |
| data_template_rrd         |
| graph_local               |
| graph_template_input      |
| graph_template_input_defs |
| graph_templates           |
| graph_templates_gprint    |
| graph_templates_graph     |
| graph_templates_item      |
| graph_tree                |
| graph_tree_items          |
| host                      |
| host_graph                |
| host_snmp_cache           |
| host_snmp_query           |
| host_template             |
| host_template_graph       |
| host_template_snmp_query  |
| plugin_config             |
| plugin_db_changes         |
| plugin_hooks              |
| plugin_realms             |
| poller                    |
| poller_command            |
| poller_item               |
| poller_output             |
| poller_reindex            |
| poller_time               |
| rra                       |
| rra_cf                    |
| settings                  |
| settings_graphs           |
| settings_tree             |
| snmp_query                |
| snmp_query_graph          |
| snmp_query_graph_rrd      |
| snmp_query_graph_rrd_sv   |
| snmp_query_graph_sv       |
| user_auth                 |
| user_auth_perms           |
| user_auth_realm           |
| user_log                  |
| version                   |
+---------------------------+
52 rows in set (0.00 sec)

mysql> use cacti2;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+--------------------------------+
| Tables_in_cacti2               |
+--------------------------------+
| cdef                           |
| cdef_items                     |
| colors                         |
| data_input                     |
| data_input_data                |
| data_input_fields              |
| data_local                     |
| data_template                  |
| data_template_data             |
| data_template_data_rra         |
| data_template_rrd              |
| graph_local                    |
| graph_template_input           |
| graph_template_input_defs      |
| graph_templates                |
| graph_templates_gprint         |
| graph_templates_graph          |
| graph_templates_item           |
| graph_tree                     |
| graph_tree_items               |
| host                           |
| host_graph                     |
| host_snmp_cache                |
| host_snmp_query                |
| host_template                  |
| host_template_graph            |
| host_template_snmp_query       |
| plugin_config                  |
| plugin_db_changes              |
| plugin_discover_hosts          |
| plugin_discover_template       |
| plugin_flowview_devices        |
| plugin_flowview_dnscache       |
| plugin_flowview_ports          |
| plugin_flowview_queries        |
| plugin_flowview_schedules      |
| plugin_hooks                   |
| plugin_notification_lists      |
| plugin_realms                  |
| plugin_thold_contacts          |
| plugin_thold_host_failed       |
| plugin_thold_log               |
| plugin_thold_template_contact  |
| plugin_thold_threshold_contact |
| poller                         |
| poller_command                 |
| poller_item                    |
| poller_output                  |
| poller_reindex                 |
| poller_time                    |
| rra                            |
| rra_cf                         |
| settings                       |
| settings_graphs                |
| settings_tree                  |
| snmp_query                     |
| snmp_query_graph               |
| snmp_query_graph_rrd           |
| snmp_query_graph_rrd_sv        |
| snmp_query_graph_sv            |
| syslog                         |
| syslog_alert                   |
| syslog_facilities              |
| syslog_host_facilities         |
| syslog_hosts                   |
| syslog_incoming                |
| syslog_logs                    |
| syslog_priorities              |
| syslog_remove                  |
| syslog_removed                 |
| syslog_reports                 |
| syslog_statistics              |
| thold_data                     |
| thold_template                 |
| user_auth                      |
| user_auth_perms                |
| user_auth_realm                |
| user_log                       |
| version                        |
+--------------------------------+
79 rows in set (0.00 sec)
user3766148
  • 298
  • 2
  • 4
  • 11

2 Answers2

1

I recently successfully upgraded a borked 0.8.8c database to Cacti 1.2.x. Someone had installed it years ago, used a cronjob from the newer Cacti version, but the files from the older one and a DB version somewhere inbetween.


This is how I did it:

  1. Install newest Cacti, Spine and what I had installed on the old server onto the new one
  2. rsync --ignore-existing cacti/resource/snmp_queries/*.xml cacti/scripts/* newserver:.
  3. create empty DB
  4. edit /etc/spine.conf and /etc/cacti/db.php with the new credentials
  5. copy over the old DB, mysqldump < old_db.sql
  6. repair the DB with php /var/lib/cacti/cli/repair_database.php
  7. upgrade the DB with php /var/lib/cacti/cli/upgrade_database.php

You may have to repair the DB after upgrade again. After I had upgraded the DB I still had some settings to change which I did directly in the database before visiting Cacti in my browser. For that you can show all paths in the settings with SELECT * FROM settings WHERE VALUE LIKE '%/%'.

If you had Cacti installed manually on the old system or if you use a different distribution now, the paths might be wrong. Fix it with UPDATE settings SET VALUE = REPLACE(VALUE, '/var/www/html/cacti', '/usr/share/cacti'); (of course replace the paths to the ones relevant to you).


For me even the paths to spine and rrdtool were wrong. I had to change them with:

UPDATE settings SET VALUE = '/usr/bin/spine' WHERE name = 'path_spine';
UPDATE settings SET VALUE = '/usr/bin/rrdtool' WHERE name = 'path_rrdtool';

Finally I disabled all plugins in case there was something wrong with them via UPDATE plugin_config SET status = '0'; – I enabled them later manually.

Some reports in reports_items were wrong which I fixed with DELETE FROM reports_items WHERE 'id' = 123;. Of course you have to check Cacti's logs to find out which reports are borked.

After that, remember to back up your new Cacti install and check every graph and the Cacti logs to find out if you missed something.


I replaced Cacti's Cronjob with a systemd unit/timer for better logging and reproducibility of executions. This is my cacti-poller.service:

[Unit]
Description=Cacti Poller

[Service]
Type=oneshot
ExecStart=/usr/bin/php /usr/share/cacti/poller.php

and this is the corresponding cacti-poller.timer:

[Unit]
Description=Run cacti poller every 5 minutes

[Timer]
OnCalendar=*:0/5
Unit=cacti-poller.service
AccuracySec=1s

This is also documented in the Arch Wiki. Please also have a look at the Cacti Docs which were posted here already.

Luca
  • 11
  • 2
0

The recommended upgrade procedure appears to be to:

  • back-up the existing database
  • upgrade cacti
  • then let cacti upgrade the existing database schema,

rather than creating a new database and trying for a manual data migration.

HBruijn
  • 77,029
  • 24
  • 135
  • 201