NETWORK & SEVER FACTORY

개인 공부 기록

Server/Monitoring

[ZABBIX] DB 백업 및 복원

1nfra 2022. 10. 7. 02:42
728x90

안녕하세요 ~

 

오늘은 Zabbix를 다른 서버로 옮기기 위해 설정값을 백업 후 복원하는 방법에 대해 알아보겠습니다.

 

먼저 아래 링크에서 Source 코드를 다운로드한 후 데이터 백업이 필요한 Zabbix 서버로 옮겨줍니다.

 

https://github.com/maxhq/zabbix-backup/wiki

 

GitHub - maxhq/zabbix-backup: Backup script for Zabbix configuration data (MySQL/PostgreSQL)

Backup script for Zabbix configuration data (MySQL/PostgreSQL) - GitHub - maxhq/zabbix-backup: Backup script for Zabbix configuration data (MySQL/PostgreSQL)

github.com

 

우선 옮긴 파일을 tar 명령어로 압축을 풀어줍니다.

[root@zabbix ~]# tar -xvf zabbix-backup-0.9.3.tar.gz
zabbix-backup-0.9.3/
zabbix-backup-0.9.3/.gitignore
zabbix-backup-0.9.3/LICENSE.txt
zabbix-backup-0.9.3/README.md
zabbix-backup-0.9.3/RELEASE.md
zabbix-backup-0.9.3/get-table-list.pl
zabbix-backup-0.9.3/zabbix-dump
[root@zabbix ~]# ls
zabbix-backup-0.9.3  zabbix-backup-0.9.3.tar.gz
[root@zabbix ~]#

 

 아래 명령어로 Zabbix 데이터를 백업해줍니다.

[root@zabbix ~]# ./zabbix-backup-0.9.3/zabbix-dump
Reading database options from /etc/zabbix/zabbix_server.conf...
Configuration:
 - type:     mysql
 - socket:   /var/lib/mysql/mysql.sock
 - database: zabbix
 - user:     zabbix
 - output:   /root
Fetching list of existing tables...
Starting table backups...

For the following large tables only the schema (without data) was stored:
 - acknowledges
 - alerts
 - auditlog
 - auditlog_details
 - event_recovery
 - events
 - event_suppress
 - event_tag
 - history
 - history_log
 - history_str
 - history_text
 - history_uint
 - item_rtdata
 - problem
 - problem_tag
 - task
 - task_acknowledge
 - task_check_now
 - task_close_problem
 - task_remote_command
 - task_remote_command_result
 - trends
 - trends_uint

Compressing backup file...
Backup Completed
/root/zabbix_cfg_zabbix.localdomain_20221007-0216_db-mysql-4.4.2.sql.gz
[root@zabbix ~]# ls
zabbix-backup-0.9.3         zabbix_cfg_zabbix.localdomain_20221007-0216_db-mysql-4.4.2.sql.gz
zabbix-backup-0.9.3.tar.gz
[root@zabbix ~]#

백업이 완료되면 .sql.gz 파일이 생성되게 됩니다.

 

이제 생성된 파일을 옮길 Zabbix 서버로 옮겨주면 됩니다. 

 

파일을 옮겼다면, gunzip 명령어로 압축을 풀어주세요.

 

[root@zabbix backup]# ls
zabbix_cfg_zabbix.localdomain_20221007-0145_db-mysql-4.4.2.sql.gz
[root@zabbix backup]# gunzip zabbix_cfg_zabbix.localdomain_20221007-0145_db-mysql-4.4.2.sql.gz
[root@zabbix backup]# ls
zabbix_cfg_zabbix.localdomain_20221007-0145_db-mysql-4.4.2.sql

 

다음으로는 Zabbix 데몬을 내려줍니다.

[root@zabbix ~]# systemctl stop zabbix-server zabbix-agent httpd

 

이제 mysql에 접속하여, 기존 zabbix DB를 Drop 후 새로 Create 해줍니다.

[root@zabbix ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 356
Server version: 5.7.33 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| zabbix             |
+--------------------+
5 rows in set (0.00 sec)

mysql> drop database zabbix;
Query OK, 149 rows affected (0.20 sec)

mysql> create database zabbix character set utf8;
Query OK, 1 row affected (0.00 sec)

mysql> exit
Bye

 

마지막으로 아래 명령어로 셋팅값을 넣어주면 완료됩니다.

[root@zabbix ~]# mysql -u root -p zabbix < /backup/zabbix_cfg_zabbix.localdomain_20221007-0145_db-mysql-4.4.2.sql   Enter password:
[root@zabbix ~]#

내렸던 zabbix 데몬을 실행시켜주면 셋팅값이 정상적으로 옮겨지게 됩니다. 

728x90