Zabbix DB backup and restoration

 Step 1: Take Backup (Dump)

# Go to backup directory

mkdir -p /var/backups/zabbix

cd /var/backups/zabbix


# Take dump (enter MySQL root password when asked)

mysqldump -u root -p --single-transaction --routines --triggers --events zabbix | gzip > zabbix_backup.sql.gz


# Verify dump

ls -lh zabbix_backup.sql.gz

gzip -t zabbix_backup.sql.gz && echo "Backup OK"

Step 2: Stop Zabbix services

systemctl stop zabbix-server zabbix-agent
systemctl stop apache2  # or nginx if used

systemctl stop zabbix-server zabbix-agent
systemctl stop apache2  # or nginx if used

Step 3: Simulate DB crash (drop database)
mysql -u root -p 

DROP DATABASE IF EXISTS zabbix;
SHOW DATABASES;

Step 4: Recreate empty database
mysql -u root -p -e "CREATE DATABASE zabbix CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;"

Step 5: Restore from backup
gunzip < /var/backups/zabbix/zabbix_backup.sql.gz | mysql -u root -p zabbix

Step 6: Start Zabbix services again
systemctl start mysql
systemctl start zabbix-server zabbix-agent
systemctl start apache2   # or nginx

Step 7: Verify
mysql -u root -p -e "USE zabbix; SHOW TABLES LIMIT 5;"
systemctl status zabbix-server
tail -n 50 /var/log/zabbix/zabbix_server.log


Comments

Popular posts from this blog

How to enable the syslog monitoring-Zabbix

Zabbix installation: Distribution setup

Zabbix built-in HA Vs Pacemaker/corosync