npotorino / zabbix-backup

Backup script for Zabbix configuration data (MySQL/PostgreSQL)
MIT License
67 stars 30 forks source link

Backup script for Zabbix configuration data (MySQL/PostgreSQL)

This is a MySQL/PostgreSQL database backup script for the Zabbix monitoring software from version 1.3.1 up to 6.4.

Download

Download the latest (stable) release here:

https://github.com/npotorino/zabbix-backup/releases/latest

More informations

Please see the Project Wiki.

Examples

Backup

Example: backup Zabbix with PostgreSQL and TimeScaleDB

git clone https://github.com/npotorino/zabbix-backup
cd zabbix-backup
./zabbix-dump -t psql -H localhost -P 5432 -o /var/backup

Restore

Example: restore Zabbix 5.0 with PostgreSQL and TimeScaleDB

# systemctl stop zabbix-server.service
su - postgres
dropdb zabbix
createdb -O zabbix zabbix

echo "CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;" | psql zabbix
echo "SELECT timescaledb_pre_restore();" | psql zabbix

gunzip /var/backup/zabbix_cfg_localhost_20200730-1810_db-psql-5.0.1.sql.gz
psql zabbix < /var/backup/zabbix_cfg_localhost_20200730-1810_db-psql-5.0.1.sql

echo "SELECT timescaledb_post_restore();" | psql zabbix
systemctl restart postgresql-12.service
# systemctl start zabbix-server.service

A different approach using the original schema and pg_restore with the custom format. Zabbix version: 5.0. PostgreSQL with TimescaleDB.

# systemctl stop zabbix-server.service
su - postgres
dropdb zabbix
# we assume the zabbix user already exists, if it doesnt: createuser --pwprompt zabbix
createdb -O zabbix zabbix
cat /usr/share/zabbix-postgresql/schema.sql | psql -h 127.0.0.1 -U zabbix -d zabbix
gunzip zabbix_cfg_localhost_20200730-1810_db-psql-5.0.1.sql.gz
pg_restore --disable-triggers --data-only -d zabbix zabbix_cfg_localhost_20200730-1810_db-psql-5.0.1.sql
echo "CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;" | psql zabbix
cat /usr/share/zabbix-postgresql/timescaledb.sql | psql zabbix

Version history

0.9.11 (2023-05-02)

0.9.10 (2022-09-30)

0.9.9 (2022-08-31)

0.9.8 (2022-07-27)

0.9.7 (2022-05-10)

0.9.6 (2021-12-13)

0.9.5 (2021-07-23)

0.9.4 (2021-01-21)

0.9.3 (2020-01-17)

0.9.2 (2020-01-16)

0.9.1 (2019-03-21)

0.9.0 (2019-03-14)

0.8.2 (2016-09-08)

0.8.1 (2016-07-11)

0.8.0 (2016-01-22)

0.7.1 (2015-01-27)

0.7.0 (2014-10-02)

0.6.0 (2014-09-15)

0.5.0 (2013-05-13)

0.4.0 (2012-03-02)

0.3.0 (2012-02-06)

0.2.0 (2011-11-05)