# Zabbix Database restore

We will be taking mysql database into consideration and will be using `mysqldump` utility to restore the zabbix database.

In the previous sections we have taken the database backup and we will be using the same zabbix database restore process.

{% content-ref url="/pages/N5AyGHwlOsizcAgwy8au" %}
[Zabbix Database backup](/ghoulsec-vault/security-operations/zabbix-nms/zabbix-database-management/zabbix-database-backup.md)
{% endcontent-ref %}

***

## Restoring Database

In case of any failure we will have to install the fresh mysql database copy with the same version old instance was running to ensure smooth & unintereppted restore process.

```bash
sudo apt install mysql-server
sudo systemctl enable mysql
sudo systemctl start mysql
```

We will need to make some configuration changes to ensure database accepts connection other than the localhost in case when zabbix is deployed on the multinode model.

```bash
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
```

Look for the `bind-address` directive under the `[mysqld]` section. By default, it may be set to `127.0.0.1` (localhost) to restrict connections to the local machine. Change this to `0.0.0.0` to allow MySQL to listen on all network interfaces.

```bash
[mysqld]
bind-address = 0.0.0.0
```

This will ensure mysql connection from foreign hosts but we need to add some security which we can do with `ufw` :&#x20;

```bash
sudo ufw allow from <NETWORK_RANGE> to any port 3306
sudo ufw deny from any to any port 3306
```

Now we will restart the mysql connections to ensure that all settings & configurations are applied correctly.

```
sudo systemctl restart mysql
```

> ⚠️ UFW configuration might disconnect active sessions if not configured correctly.

***

## Creating existing users on the new database

```bash
create database zabbix character set utf8mb4 collate utf8mb4_bin;
create user zabbix@<NETWORK> identified by '<SAME_OLD_DB-password>';
```

Importing the databse using the mysqldump utility :&#x20;

```bash
mysql -u username -p your_database_name < /path/to/your_backup.sql
```

Once database is restored we can enable the zabbix-server back to resume normal operations.

```bash
sudo systemctl start zabbix-server
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ghoulsec.gitbook.io/ghoulsec-vault/security-operations/zabbix-nms/zabbix-database-management/zabbix-database-restore.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
