我有一个较旧的 Cacti 数据库,里面有我试图恢复的关键数据。旧数据库的字段比新的当前稳定数据库少很多。手动导入会产生严重错误。如何将较旧的 Cacti 数据库导入当前稳定数据库?
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)
答案1
答案2
我最近成功地将一个 borked 0.8.8c 数据库升级到 Cacti 1.2.x。有人在几年前安装了它,使用了较新版本的 Cacti 中的 cronjob,但文件来自较旧的版本,并且 DB 版本介于两者之间。
我是这样做的:
- 将最新的 Cacti、Spine 以及我在旧服务器上安装的内容安装到新服务器上
rsync --ignore-existing cacti/resource/snmp_queries/*.xml cacti/scripts/* newserver:.
- 创建空数据库
- 编辑
/etc/spine.conf
并/etc/cacti/db.php
使用新凭据 - 复制旧数据库,
mysqldump < old_db.sql
- 使用以下方法修复数据库
php /var/lib/cacti/cli/repair_database.php
- 使用以下方法升级数据库
php /var/lib/cacti/cli/upgrade_database.php
升级后您可能需要再次修复数据库。升级数据库后,我仍然有一些要更改的设置我就是这么做的直接在数据库中在我的浏览器中访问 Cacti 之前。为此,您可以在设置中使用 显示所有路径SELECT * FROM settings WHERE VALUE LIKE '%/%'
。
如果你在旧系统上手动安装了 Cacti,或者你使用了其他发行版现在,路径可能不对。用以下方法修复它UPDATE settings SET VALUE = REPLACE(VALUE, '/var/www/html/cacti', '/usr/share/cacti');
(当然,请将路径替换为您所需的路径)。
对我来说,甚至 spine 和 rrdtool 的路径都是错误的。我不得不用以下方法更改它们:
UPDATE settings SET VALUE = '/usr/bin/spine' WHERE name = 'path_spine';
UPDATE settings SET VALUE = '/usr/bin/rrdtool' WHERE name = 'path_rrdtool';
最后,我禁用了所有插件,以防它们出现问题UPDATE plugin_config SET status = '0';
- 我稍后手动启用它们。
中的一些报告reports_items
是错误的,我用 进行了修复DELETE FROM reports_items WHERE 'id' = 123;
。当然,您必须检查 Cacti 的日志才能找出哪些报告有问题。
之后,请记住备份新安装的 Cacti 并检查每个图表和 Cacti 日志以查看是否遗漏了某些内容。
我使用 systemd 单元/计时器替换 Cacti 的 Cronjob以便更好地记录和重现执行。这是我的 cacti-poller.service:
[Unit]
Description=Cacti Poller
[Service]
Type=oneshot
ExecStart=/usr/bin/php /usr/share/cacti/poller.php
这是相应的 cacti-poller.timer:
[Unit]
Description=Run cacti poller every 5 minutes
[Timer]
OnCalendar=*:0/5
Unit=cacti-poller.service
AccuracySec=1s
这也记录在建筑维基。还请查看已在此处发布的 Cacti 文档。