您好,登录后才能下订单哦!
#!/bin/bash
#sadoc.blog.51cto.com
#备份zabbix数据库,不备份监控历史数据
HOST=127.0.0.1
SQL_PORT=3306
SQL_USER=zabbix
SQL_PASS=123456
DATABASE_NAME=zabbix
DUMP_PATH=/backup/mysql_backup
DATE=$(date '+%Y-%m-%d:%H:%M:%S')
DATED=$(date '+%Y-%m-%d')
[ -d ${DUMP_PATH} ] || mkdir -p ${DUMP_PATH}
cd ${DUMP_PATH}
[ -d logs ] || mkdir -p logs
[ -d ${DATED} ] || mkdir -p ${DATED}
cd ${DATED}
ALL_TABLES=$(mysql -u${SQL_USER} -p${SQL_PASS} -P${SQL_PORT} -h${HOST} ${DATABASE_NAME} -e "show tables" | \
egrep -v "(Tables_in_zabbix|trends*|acknowledges|alerts|auditlog|events|service_alarms)")
for TABLE_NAME in ${ALL_TABLES}
do
mysqldump -u${SQL_USER} -p${SQL_PASS} -P${SQL_PORT} -h${HOST} ${DATABASE_NAME} ${TABLE_NAME} > ${TABLE_NAME}.sql
sleep 10
done
[ $? = 0 ] && echo "${DATE}: Backup zabbix_mysql succeed" >> ${DUMP_PATH}/logs/zabbix_dump.log
[ $? != 0 ] && echo "${DATE}: Backup zabbix_mysql not succeed" >> ${DUMP_PATH}/logs/zabbix_dump_error.log
cd ${DUMP_PATH}/
rm -rf $(date +%Y%m%d --date='7 days ago')
exit 0
下面导入数据库:
删除数据库
drop database zabbix;
创建数据库
create database zabbix character set utf8 collate utf8_bin;
use zabbix;
source /backup/mysql_backup/xxx.sql;
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。