Zabbix Backup

Invented and sketched a couple of lines for backup mysql database and directories with http files.

First of all, we make a copy of mysql of the zabbix database (with the –ignore-table switch we exclude unnecessary history tables, since they can occupy gigabytes) and archive it:

mysqldump --ignore-table=zabbix.history --ignore-table=zabbix.history_uint --ignore-table=zabbix.trends --ignore-table=zabbix.trends_uint -u USERNAME -h localhost -pPASSWORD zabbix | gzip -c > /backups/zabbix_`date +%Y-%m-%d`.sql.gz

The second step is to archive the zabbix http files:

tar -cvjf /backups/`date +%Y-%m-%d`_zabbix.tar.bz2 /usr/share/zabbix/

Instead of the /backups/ directory, you can mount and specify some kind of network drive from the Internet and make backups on it.
Both lines can be added to /etc/crontab so that copies are run daily, for example, or added to the script, give the script permission to execute, and in /etc/crontab specify the path to this script, for example every day at 3 am:

0 3 * * * root /backups/script.sh > /dev/null 2>&1

You can also not make a backup copy of http files, but simply know which version of the zabbix server is installed and then install it on the new server, create an empty zabbix database, import the dump into it, if the dump does not contain some tables with history, then we will create them manually (there are examples in the /usr/share/doc/zabbix-server-mysql directory), for example, here are a few for Zabbix 6.4.10, which I excluded from the dump:

CREATE TABLE `history` (
	`itemid`                 bigint unsigned                           NOT NULL,
	`clock`                  integer         DEFAULT '0'               NOT NULL,
	`value`                  DOUBLE PRECISION DEFAULT '0.0000'          NOT NULL,
	`ns`                     integer         DEFAULT '0'               NOT NULL,
	PRIMARY KEY (itemid,clock,ns)
) ENGINE=InnoDB;

CREATE TABLE `history_uint` (
	`itemid`                 bigint unsigned                           NOT NULL,
	`clock`                  integer         DEFAULT '0'               NOT NULL,
	`value`                  bigint unsigned DEFAULT '0'               NOT NULL,
	`ns`                     integer         DEFAULT '0'               NOT NULL,
	PRIMARY KEY (itemid,clock,ns)
) ENGINE=InnoDB;

CREATE TABLE `trends` (
	`itemid`                 bigint unsigned                           NOT NULL,
	`clock`                  integer         DEFAULT '0'               NOT NULL,
	`num`                    integer         DEFAULT '0'               NOT NULL,
	`value_min`              DOUBLE PRECISION DEFAULT '0.0000'          NOT NULL,
	`value_avg`              DOUBLE PRECISION DEFAULT '0.0000'          NOT NULL,
	`value_max`              DOUBLE PRECISION DEFAULT '0.0000'          NOT NULL,
	PRIMARY KEY (itemid,clock)
) ENGINE=InnoDB;

CREATE TABLE `trends_uint` (
	`itemid`                 bigint unsigned                           NOT NULL,
	`clock`                  integer         DEFAULT '0'               NOT NULL,
	`num`                    integer         DEFAULT '0'               NOT NULL,
	`value_min`              bigint unsigned DEFAULT '0'               NOT NULL,
	`value_avg`              bigint unsigned DEFAULT '0'               NOT NULL,
	`value_max`              bigint unsigned DEFAULT '0'               NOT NULL,
	PRIMARY KEY (itemid,clock)
) ENGINE=InnoDB;

See also my articles:
Using and configuring CRON
Script to delete old files
Zabbix installation on Ubuntu from distribution packages

Leave a comment

Leave a Reply