Перенос zabbix-сервера с небольшими плюшками

Задача: мигрировать zabbix-сервер на новую платформу с сохранением всех настроек, айтемов, триггеров, хостов и прочего исключив историю записей
В статье подразумевается, что была произведена установка и настройка zabbix-сервера с нуля и на текущий момент он абсолютно пуст.
Текущий сервер:

# rpm -qa | grep zabbix-server
zabbix-server-2.4.4-1.el6.x86_64

Новый сервер:

# rpm -qa | grep zabbix-server
zabbix-server-2.4.5-1.el7.x86_64

Так как zabbix хранит все данные в БД, то решением будет дамп всех таблиц, в имени которых не встречатся history. Есть маленький нюанс: исключить нужно только те таблицы, которые начинаются с history

# mysql -uzabbix -p -h127.0.0.1 -Bse "select table_name from information_schema.tables where table_schema = 'zabbix' and engine = 'InnoDB'" | grep history
Enter password:
history
history_log
history_str
history_text
history_uint
proxy_dhistory
proxy_history
user_history

как видим кроме общей истории zabbix сохраняет историю прокси и пользователей, которую мы оставим.
Сделаем мы это следующим образом:
Запросом получим от сервера список всех таблиц в БД, исключим из них те, которые начинаются с history и сделаем дамп каждой в отдельный архив:

#!/bin/bash
### MySQL Server Login Info ###
MUSER="zabbix"
MPASS="zabbix"
MDB="zabbix"

TABLES_INNODB="$(mysql -u$MUSER -p$MPASS -h127.0.0.1 -Bse "select table_name from information_schema.tables where table_schema = '$MDB' and engine = 'InnoDB'")"
### Job ###

mkdir -p /root/full
cd /root/full

#InnoDB Dump
for table_i in $TABLES_INNODB
 do
  if [[ $table_i == "history"* ]]
  then
   echo "The table name contain \"history\""
  else
   echo "Dump $table_i started $(date +"%d %B %Y") at $(date +"%H:%M:%S")"
   mysqldump -u$MUSER -p$MPASS -h127.0.0.1 $MDB --skip-lock-tables --single-transaction --quick --tables $table_i | gzip -9 > $table_i.sql.gz
   echo "Dump $table_i ended $(date +"%d %B %Y") at $(date +"%H:%M:%S")"
  fi
 done

Получаем следующий вывод:

# sh /root/dump_no_history.sh
Dump acknowledges started 14 May 2015 at 16:56:04
Dump acknowledges ended 14 May 2015 at 16:56:04
Dump actions started 14 May 2015 at 16:56:04
Dump actions ended 14 May 2015 at 16:56:04
Dump alerts started 14 May 2015 at 16:56:04
Dump alerts ended 14 May 2015 at 16:56:04
Dump application_template started 14 May 2015 at 16:56:04
Dump application_template ended 14 May 2015 at 16:56:04
Dump applications started 14 May 2015 at 16:56:04
Dump applications ended 14 May 2015 at 16:56:04
Dump auditlog started 14 May 2015 at 16:56:04
Dump auditlog ended 14 May 2015 at 16:56:06
Dump auditlog_details started 14 May 2015 at 16:56:06
Dump auditlog_details ended 14 May 2015 at 16:56:06
Dump autoreg_host started 14 May 2015 at 16:56:06
Dump autoreg_host ended 14 May 2015 at 16:56:06
Dump conditions started 14 May 2015 at 16:56:06
Dump conditions ended 14 May 2015 at 16:56:06
Dump config started 14 May 2015 at 16:56:06
Dump config ended 14 May 2015 at 16:56:06
Dump dbversion started 14 May 2015 at 16:56:06
Dump dbversion ended 14 May 2015 at 16:56:06
Dump dchecks started 14 May 2015 at 16:56:06
Dump dchecks ended 14 May 2015 at 16:56:06
Dump dhosts started 14 May 2015 at 16:56:06
Dump dhosts ended 14 May 2015 at 16:56:06
Dump drules started 14 May 2015 at 16:56:06
Dump drules ended 14 May 2015 at 16:56:06
Dump dservices started 14 May 2015 at 16:56:06
Dump dservices ended 14 May 2015 at 16:56:06
Dump escalations started 14 May 2015 at 16:56:06
Dump escalations ended 14 May 2015 at 16:56:06
Dump events started 14 May 2015 at 16:56:06
Dump events ended 14 May 2015 at 16:56:50
Dump expressions started 14 May 2015 at 16:56:50
Dump expressions ended 14 May 2015 at 16:56:50
Dump functions started 14 May 2015 at 16:56:50
Dump functions ended 14 May 2015 at 16:56:50
Dump globalmacro started 14 May 2015 at 16:56:50
Dump globalmacro ended 14 May 2015 at 16:56:50
Dump globalvars started 14 May 2015 at 16:56:50
Dump globalvars ended 14 May 2015 at 16:56:50
Dump graph_discovery started 14 May 2015 at 16:56:50
Dump graph_discovery ended 14 May 2015 at 16:56:50
Dump graph_theme started 14 May 2015 at 16:56:50
Dump graph_theme ended 14 May 2015 at 16:56:50
Dump graphs started 14 May 2015 at 16:56:50
Dump graphs ended 14 May 2015 at 16:56:50
Dump graphs_items started 14 May 2015 at 16:56:50
Dump graphs_items ended 14 May 2015 at 16:56:50
Dump group_discovery started 14 May 2015 at 16:56:50
Dump group_discovery ended 14 May 2015 at 16:56:50
Dump group_prototype started 14 May 2015 at 16:56:50
Dump group_prototype ended 14 May 2015 at 16:56:50
Dump groups started 14 May 2015 at 16:56:50
Dump groups ended 14 May 2015 at 16:56:50
The table name contain "history"
The table name contain "history"
The table name contain "history"
The table name contain "history"
The table name contain "history"
Dump host_discovery started 14 May 2015 at 16:56:50
Dump host_discovery ended 14 May 2015 at 16:56:50
Dump host_inventory started 14 May 2015 at 16:56:50
Dump host_inventory ended 14 May 2015 at 16:56:50
Dump hostmacro started 14 May 2015 at 16:56:50
Dump hostmacro ended 14 May 2015 at 16:56:50
Dump hosts started 14 May 2015 at 16:56:50
Dump hosts ended 14 May 2015 at 16:56:50
Dump hosts_groups started 14 May 2015 at 16:56:50
Dump hosts_groups ended 14 May 2015 at 16:56:51
Dump hosts_templates started 14 May 2015 at 16:56:51
Dump hosts_templates ended 14 May 2015 at 16:56:51
Dump housekeeper started 14 May 2015 at 16:56:51
Dump housekeeper ended 14 May 2015 at 16:56:51
Dump httpstep started 14 May 2015 at 16:56:51
Dump httpstep ended 14 May 2015 at 16:56:51
Dump httpstepitem started 14 May 2015 at 16:56:51
Dump httpstepitem ended 14 May 2015 at 16:56:51
Dump httptest started 14 May 2015 at 16:56:51
Dump httptest ended 14 May 2015 at 16:56:51
Dump httptestitem started 14 May 2015 at 16:56:51
Dump httptestitem ended 14 May 2015 at 16:56:51
Dump icon_map started 14 May 2015 at 16:56:51
Dump icon_map ended 14 May 2015 at 16:56:51
Dump icon_mapping started 14 May 2015 at 16:56:51
Dump icon_mapping ended 14 May 2015 at 16:56:51
Dump ids started 14 May 2015 at 16:56:51
Dump ids ended 14 May 2015 at 16:56:51
Dump images started 14 May 2015 at 16:56:51
Dump images ended 14 May 2015 at 16:56:51
Dump interface started 14 May 2015 at 16:56:51
Dump interface ended 14 May 2015 at 16:56:51
Dump interface_discovery started 14 May 2015 at 16:56:51
Dump interface_discovery ended 14 May 2015 at 16:56:51
Dump item_condition started 14 May 2015 at 16:56:51
Dump item_condition ended 14 May 2015 at 16:56:51
Dump item_discovery started 14 May 2015 at 16:56:51
Dump item_discovery ended 14 May 2015 at 16:56:51
Dump items started 14 May 2015 at 16:56:51
Dump items ended 14 May 2015 at 16:56:51
Dump items_applications started 14 May 2015 at 16:56:51
Dump items_applications ended 14 May 2015 at 16:56:52
Dump maintenances started 14 May 2015 at 16:56:52
Dump maintenances ended 14 May 2015 at 16:56:52
Dump maintenances_groups started 14 May 2015 at 16:56:52
Dump maintenances_groups ended 14 May 2015 at 16:56:52
Dump maintenances_hosts started 14 May 2015 at 16:56:52
Dump maintenances_hosts ended 14 May 2015 at 16:56:52
Dump maintenances_windows started 14 May 2015 at 16:56:52
Dump maintenances_windows ended 14 May 2015 at 16:56:52
Dump mappings started 14 May 2015 at 16:56:52
Dump mappings ended 14 May 2015 at 16:56:52
Dump media started 14 May 2015 at 16:56:52
Dump media ended 14 May 2015 at 16:56:52
Dump media_type started 14 May 2015 at 16:56:52
Dump media_type ended 14 May 2015 at 16:56:52
Dump opcommand started 14 May 2015 at 16:56:52
Dump opcommand ended 14 May 2015 at 16:56:52
Dump opcommand_grp started 14 May 2015 at 16:56:52
Dump opcommand_grp ended 14 May 2015 at 16:56:52
Dump opcommand_hst started 14 May 2015 at 16:56:52
Dump opcommand_hst ended 14 May 2015 at 16:56:52
Dump opconditions started 14 May 2015 at 16:56:52
Dump opconditions ended 14 May 2015 at 16:56:52
Dump operations started 14 May 2015 at 16:56:52
Dump operations ended 14 May 2015 at 16:56:52
Dump opgroup started 14 May 2015 at 16:56:52
Dump opgroup ended 14 May 2015 at 16:56:52
Dump opmessage started 14 May 2015 at 16:56:52
Dump opmessage ended 14 May 2015 at 16:56:52
Dump opmessage_grp started 14 May 2015 at 16:56:52
Dump opmessage_grp ended 14 May 2015 at 16:56:52
Dump opmessage_usr started 14 May 2015 at 16:56:52
Dump opmessage_usr ended 14 May 2015 at 16:56:52
Dump optemplate started 14 May 2015 at 16:56:52
Dump optemplate ended 14 May 2015 at 16:56:52
Dump profiles started 14 May 2015 at 16:56:52
Dump profiles ended 14 May 2015 at 16:56:52
Dump proxy_autoreg_host started 14 May 2015 at 16:56:52
Dump proxy_autoreg_host ended 14 May 2015 at 16:56:52
Dump proxy_dhistory started 14 May 2015 at 16:56:52
Dump proxy_dhistory ended 14 May 2015 at 16:56:52
Dump proxy_history started 14 May 2015 at 16:56:52
Dump proxy_history ended 14 May 2015 at 16:56:52
Dump regexps started 14 May 2015 at 16:56:52
Dump regexps ended 14 May 2015 at 16:56:52
Dump rights started 14 May 2015 at 16:56:52
Dump rights ended 14 May 2015 at 16:56:52
Dump screens started 14 May 2015 at 16:56:52
Dump screens ended 14 May 2015 at 16:56:52
Dump screens_items started 14 May 2015 at 16:56:52
Dump screens_items ended 14 May 2015 at 16:56:52
Dump scripts started 14 May 2015 at 16:56:52
Dump scripts ended 14 May 2015 at 16:56:52
Dump service_alarms started 14 May 2015 at 16:56:52
Dump service_alarms ended 14 May 2015 at 16:56:52
Dump services started 14 May 2015 at 16:56:52
Dump services ended 14 May 2015 at 16:56:53
Dump services_links started 14 May 2015 at 16:56:53
Dump services_links ended 14 May 2015 at 16:56:53
Dump services_times started 14 May 2015 at 16:56:53
Dump services_times ended 14 May 2015 at 16:56:53
Dump sessions started 14 May 2015 at 16:56:53
Dump sessions ended 14 May 2015 at 16:56:55
Dump slides started 14 May 2015 at 16:56:55
Dump slides ended 14 May 2015 at 16:56:55
Dump slideshows started 14 May 2015 at 16:56:55
Dump slideshows ended 14 May 2015 at 16:56:55
Dump sysmap_element_url started 14 May 2015 at 16:56:55
Dump sysmap_element_url ended 14 May 2015 at 16:56:55
Dump sysmap_url started 14 May 2015 at 16:56:55
Dump sysmap_url ended 14 May 2015 at 16:56:55
Dump sysmaps started 14 May 2015 at 16:56:55
Dump sysmaps ended 14 May 2015 at 16:56:55
Dump sysmaps_elements started 14 May 2015 at 16:56:55
Dump sysmaps_elements ended 14 May 2015 at 16:56:55
Dump sysmaps_link_triggers started 14 May 2015 at 16:56:55
Dump sysmaps_link_triggers ended 14 May 2015 at 16:56:55
Dump sysmaps_links started 14 May 2015 at 16:56:55
Dump sysmaps_links ended 14 May 2015 at 16:56:55
Dump timeperiods started 14 May 2015 at 16:56:55
Dump timeperiods ended 14 May 2015 at 16:56:55
Dump trends started 14 May 2015 at 16:56:55
Dump trends ended 14 May 2015 at 16:58:04
Dump trends_uint started 14 May 2015 at 16:58:04
Dump trends_uint ended 14 May 2015 at 16:58:43
Dump trigger_depends started 14 May 2015 at 16:58:43
Dump trigger_depends ended 14 May 2015 at 16:58:43
Dump trigger_discovery started 14 May 2015 at 16:58:43
Dump trigger_discovery ended 14 May 2015 at 16:58:43
Dump triggers started 14 May 2015 at 16:58:43
Dump triggers ended 14 May 2015 at 16:58:43
Dump user_history started 14 May 2015 at 16:58:43
Dump user_history ended 14 May 2015 at 16:58:43
Dump users started 14 May 2015 at 16:58:43
Dump users ended 14 May 2015 at 16:58:43
Dump users_groups started 14 May 2015 at 16:58:43
Dump users_groups ended 14 May 2015 at 16:58:43
Dump usrgrp started 14 May 2015 at 16:58:43
Dump usrgrp ended 14 May 2015 at 16:58:43
Dump valuemaps started 14 May 2015 at 16:58:43
Dump valuemaps ended 14 May 2015 at 16:58:43

Отправка полученного каталога на новый сервер:

# scp -r /root/full/ root@newhost.example.com:/root/

Импортируем дампы всех таблиц: получаем список всех архивов и поочерёдно в цикле загоняем данные в БД

# cat /root/zabbix_import.sh
#/bin/bash
MUSER="zabbix"
MPASS="zabbix"
MDB="zabbix"

LIST=$(ls /root/full/)

cd /root/full/
#echo $LIST

for i in $LIST
do
 echo "import $i"
 zcat $i | mysql -u$MUSER -p$MPASS $MDB
 echo "import done!"
done

После этого на новом zabbix сервере появились все необходимые инстансы.
zabbix

Добавить комментарий