zabbix历史数据库清除,数据库瘦身脚本分享

没清除之前的数据库大小:

查看各个表的大小:

下面是数据库脚本分享:

 #!/bin/bash
 # date:2020-01-17 10:50:22
 # version:1.0
 # name:wangxuejin
 # by zabbix history mysql_data delete
 ##############################################################
 User="zabbix"
 Passwd="xxxxxx"
 Date=date -d $(date -d "-90 day" +%Y%m%d) +%s #取7天之前的时间戳
 MYSQL=/usr/local/mysql/bin/mysql
 $MYSQL -u${User} -p${Passwd} -e "
 use zabbix;
 DELETE FROM history WHERE 'clock' < $Date;
 optimize table history;
 DELETE FROM history_str WHERE 'clock' < $Date;
 optimize table history_str;
 DELETE FROM history_uint WHERE 'clock' < $Date;
 optimize table history_uint;
 DELETE FROM history_text WHERE 'clock' < $Date;
 optimize table history_text;
 DELETE FROM  trends WHERE 'clock' < $Date;
 optimize table  trends;
 DELETE FROM trends_uint WHERE 'clock' < $Date;
 optimize table trends_uint;
 DELETE FROM events WHERE 'clock' < $Date;
 optimize table events;
 "

查看缩减之后的大小:

成功缩减了18G!

发表评论

登录... 后才能评论