Advertisement
maxhq

Configuration Backup Script for Zabbix 2.0 with MySQL

May 13th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. #
  3. # zabbix-mysql-backupconf.sh
  4. # v0.4 - 20120302 Incorporated mysqldump options suggested by Jonathan Bayer
  5. # v0.3 - 20120206 Backup of Zabbix 1.9.x / 2.0.0, removed unnecessary use of
  6. #                 variables (DATEBIN etc) for commands that use to be in $PATH
  7. # v0.2 - 20111105
  8. #
  9. # Configuration Backup for Zabbix 2.0 w/MySQL
  10. #
  11. # Author: Ricardo Santos (rsantos at gmail.com)
  12. # http://zabbixzone.com/zabbix/backuping-only-the-zabbix-configuration/
  13. #
  14. # modified by Jens Berthold, 2012
  15. #
  16. # Thanks for suggestions from:
  17. # - Oleksiy Zagorskyi (zalex)
  18. # - Petr Jendrejovsky
  19. # - Jonathan Bayer
  20. #
  21.  
  22. #
  23. # mysql config
  24. #
  25. DBHOST="1.2.3.4"
  26. DBNAME="zabbixdb"
  27. DBUSER="zabbix"
  28. DBPASS="password"
  29.  
  30. #
  31. # target path
  32. #
  33.  
  34. #MAINDIR="/var/lib/zabbix/backupconf"
  35. # following will store the backup in a subdirectory of the current directory
  36. MAINDIR="`dirname \"$0\"`"
  37.  
  38. if [ ! -x /usr/bin/mysqldump ]; then
  39.     echo "mysqldump not found."
  40.     echo "(with Debian, \"apt-get install mysql-client\" will help)"
  41.     exit 1
  42. fi
  43.  
  44. DUMPDIR="${MAINDIR}/`date +%Y%m%d-%H%M`"
  45. mkdir -p "${DUMPDIR}"
  46.  
  47. # configuration tables
  48. CONFTABLES=( actions applications autoreg_host conditions config dchecks \
  49. dhosts drules dservices escalations expressions functions globalmacro \
  50. globalvars graph_discovery graph_theme graphs graphs_items groups help_items \
  51. host_inventory hostmacro hosts hosts_groups hosts_templates housekeeper \
  52. httpstep httpstepitem httptest httptestitem icon_map icon_mapping ids images \
  53. interface item_discovery items items_applications maintenances \
  54. maintenances_groups maintenances_hosts maintenances_windows mappings media \
  55. media_type node_cksum nodes opcommand opcommand_grp opcommand_hst opconditions \
  56. operations opgroup opmessage opmessage_grp opmessage_usr optemplate profiles \
  57. proxy_autoreg_host proxy_dhistory proxy_history regexps rights screens \
  58. screens_items scripts service_alarms services services_links services_times \
  59. sessions slides slideshows sysmap_element_url sysmap_url sysmaps \
  60. sysmaps_elements sysmaps_link_triggers sysmaps_links timeperiods \
  61. trigger_depends trigger_discovery triggers user_history users users_groups \
  62. usrgrp valuemaps )
  63.  
  64. # tables with large data
  65. DATATABLES=( acknowledges alerts auditlog_details auditlog events \
  66. history history_log history_str history_str_sync history_sync history_text \
  67. history_uint history_uint_sync trends trends_uint )
  68.  
  69. DUMPFILE="${DUMPDIR}/zbx-conf-bkup-`date +%Y%m%d-%H%M`.sql"
  70. >"${DUMPFILE}"
  71.  
  72. # CONFTABLES
  73. for table in ${CONFTABLES[*]}; do
  74.     echo "Backuping configuration table ${table}"
  75.     mysqldump --routines --opt --single-transaction --skip-lock-tables --extended-insert=FALSE \
  76.         -h ${DBHOST} -u ${DBUSER} -p${DBPASS} ${DBNAME} --tables ${table} >>"${DUMPFILE}"
  77. done
  78.  
  79. # DATATABLES
  80. for table in ${DATATABLES[*]}; do
  81.     echo "Backuping data table ${table}"
  82.     mysqldump --routines --opt --single-transaction --skip-lock-tables --no-data    \
  83.         -h ${DBHOST} -u ${DBUSER} -p${DBPASS} ${DBNAME} --tables ${table} >>"${DUMPFILE}"
  84. done
  85.  
  86. gzip -f "${DUMPFILE}"
  87.  
  88. echo
  89. echo "Backup Completed - ${DUMPDIR}"
  90. echo "Hit ENTER"
  91. read
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement