#!/bin/bash #backup zabbix configure #不保存zabbix的history记录,只保存主要主机item,group,users等配置 zabbix_MySQLdump_per_table.sh source /etc/bashrc && source /etc/profile MySQL_USER=zabbix MySQL_PASSWORD=zabbix MySQL_HOST=localhost MySQL_PORT=3306 MySQL_DUMP_PATH=/mysql_backup MySQL_DATABASE_NAME=zabbix DATE=$(date '+%Y-%m-%d') [ -d ${MySQL_DUMP_PATH} ] || mkdir ${MySQL_DUMP_PATH} cd ${MySQL_DUMP_PATH} [ -d logs ] || mkdir logs [ -d ${DATE} ] || mkdir ${DATE} cd ${DATE} TABLE_NAME_ALL=$(mysql -u${MySQL_USER} -p${MySQL_PASSWORD} -P${My SQL_PORT} -h${MySQL_HOST} ${MySQL_DATABASE_NAME} -e "show tables"|egr ep -v "(Tables_in_zabbix|history*|trends*|acknowledges|alerts|auditl og|events|service_alarms)") for TABLE_NAME in ${TABLE_NAME_ALL} do mysqldump -u${MySQL_USER} -p${MySQL_PASSWORD} -P${MySQL_PORT} -h${MySQL_HOST} ${MySQL_DATABASE_NAME} ${TABLE_NAME} >${TABLE_NAME}. sql sleep 1 done [ "$?" == 0 ] && echo "${DATE}: Backup zabbix succeed" >> ${MyS QL_DUMP_PATH}/logs/ZabbixMysqlDump.log [ "$?" != 0 ] && echo "${DATE}: Backup zabbix not succeed" >> ${MyS QL_DUMP_PATH}/logs/ZabbixMysqlDump.log cd ${MySQL_DUMP_PATH}/ rm -rf $(date +%Y%m%d --date='5 days ago') exit 0
zabbix前端的所有操作都是存在数据库里的,在数据库里都会有对应的表,所以对zabbix备份,只需备份zabbix数据库就行了。使用最广泛的备份方法还是使用mysqldump
一:全库备份
[root@zabbix ~]# mysqldump -uroot -p123456 --opt zabbix | bzip2 > zabbix.sql.bz2
[root@zabbix ~]# ll zabbix.sql.bz2
-rw-r--r-- 1 root root 2353816 10-23 00:54 zabbix.sql.bz2
#--opt Same as --add-drop-table, --add-locks, --create-options,
--quick, --extended-insert, --lock-tables, --set-charset,
and --disable-keys. Enabled by default, disable with
--skip-opt.
--ignore-table跳过不需要备份的表,例如 -ignore-table=history
#由于zabbix库一般比较大,所以使用bzip2进行压缩
测试恢复:
[root@zabbix ~]# mysql -uzabbix -pzabbix zabbix < zabbix_config.sql
然后web登录页面查看是否正常
转载于:https://blog.51cto.com/2493919/1613730