删除zabbix数据库日志

时间:2020-12-16 14:46:38

#!/bin/bash
user="root"
passwd="361way"
timedate=`date -d $(date -d "-90 day" +%Y%m%d) +%s` #取90天之前的时间戳
$(which mysql) -u${user} -p${passwd} -e "
use zabbix;
DELETE FROM history WHERE 'clock' < $timedate;
optimize table history;
DELETE FROM history_str WHERE 'clock' < $timedate;
optimize table history_str;
DELETE FROM history_uint WHERE 'clock' < $timedate;
optimize table history_uint;
DELETE FROM  trends WHERE 'clock' < $timedate;
optimize table  trends;
DELETE FROM trends_uint WHERE 'clock' < $timedate;
optimize table trends_uint;
DELETE FROM events WHERE 'clock' < $timedate;
optimize table events;
"