以下是脚本代码truncate.sh:

#!/bin/bash
#User="zabbixuser"
#Passwd="zabbixpass"
systemctl stop zabbix-server.service
systemctl stop zabbix-agent.service
#$(which mysql) -u${User} -p${Passwd} -e "
$(which mysql)  -e " 
SET foreign_key_checks=0;
use zabbix;
truncate table history;
optimize table history;
truncate table history_uint;
optimize table history_uint;
truncate table history_str;
optimize table history_str;
truncate table history_text;
optimize table history_text;
truncate table history_log;
optimize table history_log;
truncate table trends;
optimize table trends;
truncate table trends_uint;
optimize table trends_uint;
truncate table problem;
optimize table problem;
truncate table events;
optimize table events;
truncate table event_recovery;
optimize table event_recovery;
SET foreign_key_checks=1;
"
#mysqldump -u${User} -p${Passwd} --quick --single-transaction zabbix |gzip >/home/`date
mysqldump --quick --single-transaction zabbix |gzip >/home/`date +%F_%H%M%S`_zabbix.sql.gz
systemctl start zabbix-server.service
systemctl start zabbix-agent.service

##########以上是脚本内容##############

关于mysql密码自己根据实际设置。

执行脚本:

sh truncate.sh

 

更多推荐