---
title: "Data source: pg_basebackup"
sidebar_label: "pg_basebackup"
description: Configure DBLab Engine to build a physical data directory from a Postgres source using pg_basebackup as a custom physical restore tool.
---

:::info
As the first step, you need to set up a machine for DBLab Engine instance. See the [guide](/docs/dblab-howtos/administration/install-dle-manually).
:::

## Configuration
### Jobs
To set up DBLab Engine to automatically get the data from a database using [pg_basebackup](https://www.postgresql.org/docs/current/app-pgbasebackup.html), use the following jobs:
- [physicalRestore](/docs/reference-guides/database-lab-engine-configuration-reference#job-physicalrestore)
- [physicalSnapshot](/docs/reference-guides/database-lab-engine-configuration-reference#job-physicalsnapshot)

### Options
Copy the contents of configuration example [`config.example.physical_generic.yml`](https://gitlab.com/postgres-ai/database-lab/-/blob/v4.2.0/engine/configs/config.example.physical_generic.yml) from the DBLab Engine repository to `~/.dblab/engine/configs/server.yml` and update the following options:
- Set a secure `server:verificationToken` — it will be used to authorize API requests to the Engine. The 4.2 example uses the placeholder `${DBLAB_VERIFICATION_TOKEN}`: either replace it with the token, or keep it and pass the variable to the container with `--env-file /etc/dblab/engine.env` (a root-owned file with mode 600 holding `DBLAB_VERIFICATION_TOKEN=...`; see [Environment variables](/docs/reference-guides/database-lab-engine-configuration-reference#environment-variables)); the engine does not start while the variable is unset
- Set connection options in `physicalRestore:options:envs`:
    - `PGUSER`: database user name
    - `PGPASSWORD`: database master password
    - `PGHOST`: database server host
- Set PostgreSQL commands in `physicalRestore:options:customTool`:
    - `command`: `pg_basebackup -X stream -D /var/lib/dblab/dblab_pool/data`
    - `restore_command`: `TBD`
- Set a proper version in Postgres Docker image tag (change the image itself only if you know what you are doing):
    - `databaseContainer:dockerImage`

## Run DBLab Engine
```bash
sudo docker run \
  --name dblab_server \
  --label dblab_control \
  --privileged \
  --publish 127.0.0.1:2345:2345 \
  --volume /var/run/docker.sock:/var/run/docker.sock \
  --volume /var/lib/dblab:/var/lib/dblab/:rshared \
  --volume ~/.dblab/engine/configs:/home/dblab/configs \
  --volume ~/.dblab/engine/meta:/home/dblab/meta \
  --volume ~/.dblab/engine/logs:/home/dblab/logs \
  --volume /sys/kernel/debug:/sys/kernel/debug:rw \
  --volume /lib/modules:/lib/modules:ro \
  --volume /proc:/host_proc:ro \
  --detach \
  --restart on-failure \
  postgresai/dblab-server:4.2.0
```

:::info
Parameter `--publish 127.0.0.1:2345:2345` means that only local connections will be allowed.

To allow external connections, consider either using additional software such as NGINX or Envoy or changing this parameter. Removing the host/IP part (`--publish 2345:2345`) allows listening to all available network interfaces.
See more details in the official [Docker command-line reference](https://docs.docker.com/engine/reference/commandline/run/#publish-or-expose-port--p---expose).
:::

## Restart in the case of failure
```bash
TBD
```
