daily pastebin goal
16%
SHARE
TWEET

Configuration Backup Script for Zabbix 1.8 with MySQL

xsbr May 30th, 2011 4,413 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.2 - 20111105
  5. #
  6. # Configuration Backup for Zabbix 1.8 w/MySQL
  7. #
  8. # Author: Ricardo Santos (rsantos at gmail.com)
  9. # http://zabbixzone.com
  10. #
  11. # Thanks for suggestions from:
  12. # - Oleksiy Zagorskyi (zalex)
  13. # - Petr Jendrejovsky
  14. #
  15.  
  16. # mysql config
  17. DBHOST="localhost"
  18. DBNAME="zabbix"
  19. DBUSER="zabbix"
  20. DBPASS="YOURMYSQLPASSWORDHERE"
  21.  
  22. # some tools
  23. MYSQLDUMP="`which mysqldump`"
  24. GZIP="`which gzip`"
  25. DATEBIN="`which date`"
  26. MKDIRBIN="`which mkdir`"
  27.  
  28. # target path
  29. MAINDIR="/var/lib/zabbix/backupconf"
  30. DUMPDIR="${MAINDIR}/`${DATEBIN} +%Y%m%d%H%M`"
  31. ${MKDIRBIN} -p ${DUMPDIR}
  32.  
  33. # configuration tables
  34. CONFTABLES=( actions applications autoreg_host conditions config dchecks dhosts \
  35. drules dservices escalations expressions functions globalmacro graph_theme \
  36. graphs graphs_items groups help_items hostmacro hosts hosts_groups \
  37. hosts_profiles hosts_profiles_ext hosts_templates housekeeper httpstep \
  38. httpstepitem httptest httptestitem ids images items items_applications \
  39. maintenances maintenances_groups maintenances_hosts maintenances_windows \
  40. mappings media media_type node_cksum nodes opconditions operations \
  41. opmediatypes profiles proxy_autoreg_host proxy_dhistory proxy_history regexps \
  42. rights screens screens_items scripts service_alarms services services_links \
  43. services_times sessions slides slideshows sysmaps sysmaps_elements \
  44. sysmaps_link_triggers sysmaps_links timeperiods trigger_depends triggers \
  45. user_history users users_groups usrgrp valuemaps )
  46.  
  47. # tables with large data
  48. DATATABLES=( acknowledges alerts auditlog_details auditlog events \
  49. history history_log history_str history_str_sync history_sync history_text \
  50. history_uint history_uint_sync trends trends_uint )
  51.  
  52. # CONFTABLES
  53. for table in ${CONFTABLES[*]}; do
  54.         DUMPFILE="${DUMPDIR}/${table}.sql"
  55.         echo "Backuping table ${table}"
  56.         ${MYSQLDUMP} -R --opt --extended-insert=FALSE \
  57.                 -h ${DBHOST} -u ${DBUSER} -p${DBPASS} ${DBNAME} --tables ${table} >${DUMPFILE}
  58.         ${GZIP} -f ${DUMPFILE}
  59. done
  60.  
  61. # DATATABLES
  62. for table in ${DATATABLES[*]}; do
  63.         DUMPFILE="${DUMPDIR}/${table}.sql"
  64.         echo "Backuping schema table ${table}"
  65.         ${MYSQLDUMP} -R --opt --no-data \
  66.                 -h ${DBHOST} -u ${DBUSER} -p${DBPASS} ${DBNAME} --tables ${table} >${DUMPFILE}
  67.         ${GZIP} -f ${DUMPFILE}
  68. done
  69.  
  70. echo
  71. echo "Backup Completed - ${DUMPDIR}"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top