# stop components
systemctl stop zabbix-server httpd
# make sure backend is down
ps aux|grep "[z]abbix_server"
# take a look on processes list so there are no important calls going on
mysql -e 'show full processlist;'
# create a backup of ~200 Gb table with fast compression
mysqldump --flush-logs --single-transaction --no-create-db --no-create-info zabbix history_uint | gzip --fast > /history_uint.sql.gz
# truncate data in history_uint
mysql zabbix -e 'truncate history_uint;'
# restore back data
zcat /history_uint.sql.gz | mysql zabbix
Cut only the most recent data:
rename table history_uint to history_uint_old; create table history_uint like history_uint_old;
SET SESSION SQL_LOG_BIN=0;
insert into history_uint (select * from history_uint_old where clock > UNIX_TIMESTAMP(NOW() - INTERVAL 14 DAY));
drop table history_uint_old;
Or:
RENAME TABLE history_uint TO history_uint_old; CREATE TABLE history_uint LIKE history_uint_old;
SET SESSION SQL_LOG_BIN=0;
insert into history_uint (SELECT * FROM history_uint_old WHERE clock > UNIX_TIMESTAMP('2020-05-20 00:00:00') AND clock < UNIX_TIMESTAMP('2020-05-21 00:00:00');
DROP TABLE history_uint_old;
mysqldump zabbix history_uint --where=" clock > UNIX_TIMESTAMP(NOW() - INTERVAL 1 DAY) " | gzip --fast > hisotry_uint.sql.gz
1 hour:
mysqldump zabbix history_uint --where=" clock > UNIX_TIMESTAMP(NOW() - INTERVAL 1 HOUR) " | gzip --fast > hisotry_uint.sql.gz
An alternative way to download day by day::
mysqldump zabbix history_uint_old --where=" clock > UNIX_TIMESTAMP('2020-05-19 00:00:00') and clock < UNIX_TIMESTAMP('2020-05-20 00:00:00') " | sed "s/history_uint_old/history_uint/" | gzip --fast > history_uint_old.2020-05-19.sql.gz
Or specify retention period:
mysqldump zabbix history_uint_old --where=" clock > UNIX_TIMESTAMP(NOW() - INTERVAL 1 DAY) " | sed "s/history_uint_old/history_uint/" | gzip --fast > hisotry_uint.sql.gz
No comments:
Post a Comment