您好,登錄后才能下訂單哦!
#!/bin/bash
#sadoc.blog.51cto.com
#備份zabbix數(shù)據(jù)庫,不備份監(jiān)控歷史數(shù)據(jù)
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
下面導(dǎo)入數(shù)據(jù)庫:
刪除數(shù)據(jù)庫
drop database zabbix;
創(chuàng)建數(shù)據(jù)庫
create database zabbix character set utf8 collate utf8_bin;
use zabbix;
source /backup/mysql_backup/xxx.sql;
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。