將獲救的仙人掌數據庫導入新版本
我有一個較舊的仙人掌數據庫,其中包含我正在嘗試恢復的關鍵數據。舊數據庫的欄位比新的目前穩定數據庫少得多。進行手動導入會產生嚴重錯誤。你如何將舊的 Cacti db 導入到目前的穩定中?
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)
建議的升級過程似乎是:
- 備份現有數據庫
- 升級仙人掌
- 然後讓 cacti 升級現有的數據庫模式,
而不是創建新數據庫並嘗試手動數據遷移。
我最近成功地將一個 0.8.8c 的數據庫升級到 Cacti 1.2.x。有人在幾年前安裝了它,使用了較新 Cacti 版本的 cronjob,但使用了較舊 Cacti 版本的文件和介於兩者之間的 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');
(當然將路徑替換為與您相關的路徑)。對我來說,即使是到 spin 和 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
這也記錄在Arch Wiki中。還請查看已在此處發布的 Cacti Docs。