A server that provides an REST API to interact with Postgres backups.
This tool is supposed to be installed in the same server where Barman is already set up and running.
Configure EDB repos 2.0 and install the package pg-backup-api using your
package manager.
- Clone this repository, e.g.:
git clone https://github.com/EnterpriseDB/pg-backup-api.git- Install
pg-backup-apiand its requirements:
cd pg-backup-api/pg_backup_api
sudo python3 setup.py installNote: pg_config application should be in your PATH because psycopg2 is
in the dependency tree. Besides that, you also need the libpq C library in
your system (libpq-dev package on Debian based, or libpq-devel package on
RedHat based).
As Barman user run:
pg-backup-api serveThe above comand will start up the REST API as a development server. If you
want to run the REST API as an WSGI application, use the approach described in
the Service section.
Note: by default pg-backup-api runs on port 7480. You can override that
behavior by passing --port N to serve command, being N the port to listen
on.
When running pg-backup-api as a service we set up the application to run
through gunicorn. Please install gunicorn before proceeding if it is missing
in your environment.
If you intend to run pg-backup-api from a local source directory, then you
need to set up the pg-backup-api service. Follow these steps:
- Create the gunicorn configuration file at
/etc/pg-backup-api-config.pywith the following content:
#Log and error access file
accesslog = "/var/log/barman/barman-api-access.log"
errorlog = "/var/log/barman/barman-api-error.log"
timeout = 60 # seconds
bind = "localhost:7480" # By default the service binds on localhost only
# If you need to change it and listen to in all interfaces,
# you could set "bind 0.0.0.0:7480"- Create the systemd unit at
/etc/systemd/system/pg-backup-api.servicewith the following content:
[Unit]
Description=Postgres Backup API
[Service]
Type=simple
User=barman
Group=barman
ExecStart=/usr/bin/gunicorn -c /etc/pg-backup-api-config.py pg_backup_api.app
Restart=always
[Install]
WantedBy=multi-user.targetIf you have installed the pg-backup-api package, the package installation puts
the service and configuration files in the right place for you.
Once the systemd services are in place, run the following command to enable
pg-backup-api startup on machine boot, and immediatelly start it:
systemctl enable pg-backup-api --nowNote: by default the pg-backup-api service runs on port 7480. You can
override that behavior by changing the port in /etc/pg-backup-api-config.py.
Either manually or running via gunicorn, it's possible to change some defaults by setting environment variables. We will describe and explain the most important ones here.
pg-backup-api by default loads the Barman configuration from /etc/barman.conf.
You could override that using PG_BACKUP_API_BARMAN_CONF. For example:
PG_BACKUP_API_BARMAN_CONF=/path/to/my/barman.conf pg-backup-api serveYou can check if the application is up and running by executing this command:
pg-backup-api statusThe command returns "OK" if the app is up and running.
The repository contains a tox.ini file which declares a set of test
environments that are available.
In the following sub-sections you will find more information about how to
manually run each of the tests. All of them assume you are inside the
pg_backup_api folder which can be found in the repository root directory.
Note: install tox Python module if you don't have it yet in your
environment.
You can run the flake8 linter over the code by running this command:
tox -e lintIt will check the source code, tests, and setup.py.
You can run the dependency checker pipdeptree by running this command:
tox -e depIt will print the tree of Python modules used by pg-backup-api, which can be
helpful in solving conflicts..
You can run unit tests by running this command:
tox -m testIt will run unit tests using pytest module and pytest-cov plugin for
coverage report.
Note: the command will take care of running the tests using all Python
versions which are supported by pg-backup-api and that are available in your
environment.
You can run the static type checker pyright over the source code by running
this command:
tox -m typeNote: the command will take care of running the static type checker using
all Python versions which are supported by pg-backup-api and that are
available in your environment.