# PostgreSQL database backup

#### In Xopero ONE, you can back up a variety of databases, including Oracle, MySQL, Microsoft SQL, and PostgreSQL.

***

## Prerequisites

To maintain data consistency, **Xopero** recommends using a dedicated backup type: **a file-based backup** with a pre-backup script for the **PostgreSQL** database.

{% hint style="success" %}
The pre-backup script can also be used to generate a database dump before performing a **disk-level backup**.
{% endhint %}

Database backup begins with a script that requests the database server to create a dump in a temporary directory. Once the dump is complete, **Xopero ONE** backs up the generated dump file.

**Xopero ONE** uses the `pg_dump` utility to back up **PostgreSQL** databases.

***

## Backup configuration

{% stepper %}
{% step %}
Log in to [**XMS**](#user-content-fn-1)[^1], go to the **Backup** tab (**Plans** > **Backup**) and click the **+ Add plan** button in the top toolbar.

<figure><img src="/files/RBnN3UpfVcOa5FstfJQC" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
Select **Devices** from the platforms list.

<figure><img src="/files/YjJh20RghtuHduqNyK7Z" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
In the next aside, select **one of the available** options and choose one or more devices for the plan to apply to (you can also select the plan to include all activated devices).

<figure><img src="/files/VWlkIX7TU8v53Q4KKx81" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
Define the name of the backup plan.
{% endstep %}

{% step %}
Configure your backup plan according to your needs (more information about the backup plan setup can be found in [File-level backup](/xopero-one-en/backup-and-recovery/workstations-and-servers/file-level-backup.md) and [Image-level backup](/xopero-one-en/backup-and-recovery/workstations-and-servers/image-level-backup.md) articles).
{% endstep %}

{% step %}
Go to the **Advanced settings** section and click **Edit** to customize additional options.

<figure><img src="/files/ZF2Fr0tsUk7I87qLqL6A" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
Scroll down to the **Backup scripts** section and click the **Pre-task script** toggle to turn it on.

<figure><img src="/files/GnwLiASPFjJrZoL4XHJH" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
Select the script dedicated to backing up the **PostgreSQL** database environment.

<figure><img src="/files/C6uDg4F8TMYNXMQvLFUO" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
Type your database **username** into the **Database user** field.

{% hint style="warning" %}
It is strongly recommended to create a dedicated user specifically for database backup operations.
{% endhint %}
{% endstep %}

{% step %}
Choose the user password by opening the **Password Manager**, where you can either add a new password or select an existing one.

<figure><img src="/files/vFeHKvtRimJURegY9r9z" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
Set up the script arguments — it should be entered in the **Script arguments** field as follows:

<figure><img src="/files/XeWgE6NFgPBTf3KjKIQZ" alt=""><figcaption></figcaption></figure>

```
database output_dir "pg_dump_dir" port_number
```

1. `database` — the name of the database to back up. A backup plan can target a single database or all databases. To back up all databases, use the `--all` parameter instead of specifying a database name.
2. `output_dir` — the directory where the database dump will be created; this is also the folder that **Xopero ONE** will back up.
3. `pg_dump_dir` — the path to the `pg_dump` utility. This is required only for **PostgreSQL** databases hosted on **Windows**.
4. `port_number` — required only if your **PostgreSQL** server uses a non-standard port (**other than 5432**).

{% hint style="warning" %}
**Specifying the port is optional.** If no port is provided, the default port (**5432**) will be used. Use the `port_number` parameter only if your **PostgreSQL** server uses a non-standard port.
{% endhint %}
{% endstep %}

{% step %}
You can enable the two additional options using the checkboxes:

1. **Wait for the script to continue the task** — the application will wait until the dump is ready.
2. **Fail the task if the script fails** — if the script fails, the system will notify you of the backup error.

<figure><img src="/files/tP2mV6TF6GmcRYEdTN81" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
Double-check your settings and click **Save** to close the **Advanced settings** aside.
{% endstep %}

{% step %}
After completing the configuration, click the **Save** button. The protection plan will then automatically begin protecting your devices and databases according to the schedule you defined.
{% endstep %}
{% endstepper %}

***

## Useful links and items

{% content-ref url="/pages/ZOPPjr4kLmSqnPfBTTTg" %}
[File-level backup recovery](/xopero-one-en/backup-and-recovery/workstations-and-servers/file-level-backup-recovery.md)
{% endcontent-ref %}

{% content-ref url="/pages/2kRF9D5o6i1a6aog9zXR" %}
[File-level backup](/xopero-one-en/backup-and-recovery/workstations-and-servers/file-level-backup.md)
{% endcontent-ref %}

{% content-ref url="/pages/fmxku9Sr43u0Fvr8JTt7" %}
[Restoring PostgreSQL database](/xopero-one-en/backup-and-recovery/workstations-and-servers/database-backup-recovery/restoring-postgresql-database.md)
{% endcontent-ref %}

[^1]: Xopero ONE Management Service


---

# 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://helpcenter.xopero.com/xopero-one-en/backup-and-recovery/workstations-and-servers/database-backup/postgresql-database-backup.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.
