Assign database permissions:
grant all privileges on zabbix.* to "zbxbackupuser"@"localhost" identified by "zabbix";
grant RELOAD, LOCK TABLES, PROCESS, REPLICATION CLIENT on *.* to "zbxbackupuser"@"localhost" identified by "zabbix";
prepare environment:
groupadd zbxbackupuser
useradd -g zbxbackupuser -s /bin/bash zbxbackupuser
# test connection
su - zbxbackupuser
Clean old gz archives:
find /home/zbxbackupuser/ -type f -name '*.gz' -mtime +60 -exec rm {} \;
schedule inside cron:
# test
./conf_zabbix_backup.sh
exit
# see backup sizes
ls -lah /home/zbxbackupuser/zabbix_backup
# schedule in cronjob
11 23 * * mon,tue,wed,thu,fri,sat zbxbackupuser /home/zbxbackupuser/conf_zabbix_backup.sh
11 23 * * sun zbxbackupuser /home/zbxbackupuser/full_zabbix_backup.sh
# restart cron
systemctl restart crond
# check if task show up
cat /var/log/cron
execute restore procedure:
# check if this is the right server to execute commands
hostname
# tripple make sure 'zabbix-server' daemon and/or zabbix_server binary are not running
# check in service level
systemctl status zabbix-server
systemctl stop zabbix-server
systemctl status zabbix-server
# check in process level
ps aux|grep [z]abbix
# it is OK to run zabbix_agentd
# disable at startup
systemctl disable zabbix-server
# lets insert brand new, fresh database schema
cd
# make sure there is no other files or directories which starts with "zabbix.."
ls -1
# download source
curl -L "https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/4.0.1/zabbix-4.0.1.tar.gz/download" > zabbix.tar.gz
# check the size. must be 18M
ls -lh zabbix.tar.gz
# extract archive
tar -vzxf zabbix.tar.gz -C ~
# go to dir where database schema are located
cd zabbix-*/database/mysql
# check if there is *.sql content
ls -1
# insert into database. sequence is important
mysql zabbix < schema.sql
mysql zabbix < images.sql
mysql zabbix < data.sql
# if sequence goes wrong then re-create fresh database with:
# mysql <<< 'drop database zabbix;create database zabbix character set utf8 collate utf8_bin;grant all privileges on zabbix.* to "zabbix"@"localhost" identified by "zabbix";flush privileges;'
# go back to home directory where the backup is located
cd
# restore conf
zcat conf.zabbix.gz | mysql zabbix
# create historical partitions for all 7 biggest tables. The following sql can be executed only on tables not containing any data
mysql zabbix < create.historical.partitions.sql
# start server
systemctl start zabbix-server
# check logs
cat /var/log/zabbix/zabbix_server.log
# if it says "please increase CacheSize" then please isntall correct zabbix_server.conf
cd
cat zabbix_server.conf> /etc/zabbix/zabbix_server.conf
# enable at startup
systemctl enable zabbix-server
No comments:
Post a Comment