This project provides a self-hosted solution for managing PostgreSQL databases, including backup management, database operations, monitoring, and scheduled backups.
- Multiple backup types (Full, Incremental, Differential)
- Point-in-time recovery
- Database creation and management
- Scheduled backups
- RESTful API interface
- Web interface
- Grafana dashboard with PostgreSQL metrics
-
Generate certificates
bash generate-certs.sh
-
Prepare environment variables (which are mandatory in compose.yml)
-
If you want to run s3 locally - run
docker compose -f compose.s3.yml up --wait
Otherwise, set proper address for your s3 storage in
backup-manager/config/pgbackrest.conf
,postgres/config/postgresql.conf
, then For running prometheus and grafana - you should rundocker compose -f compose.monitoring.yml up
You may run it on another host, if you do in such case, set proper address for grafana in .env.
-
Run docker-compose
docker compose -f compose.yml up
The following environment variables are required:
# PostgreSQL Configuration
POSTGRES_PASSWORD=postgres # Password for PostgreSQL
PG_VERSION=16 # PostgreSQL version
# Backup Configuration
BACKREST_VERSION=2.54.2 # pgBackRest version
BACKREST_UID={your_uid} # User ID for pgBackRest (use $(id -u))
BACKREST_GID={your_gid} # Group ID for pgBackRest (use $(id -g))
# Volume Configuration
DOCKER_VOLUME_DIRECTORY=./volume # Directory for storing backup data
GRAFANA_ADDRESS=http://localhost:3001 # address for grafana
You can use custom PostgreSQL configuration, for configuring it - edit file postgres/pg_hba.conf
, postgres/postgresql.conf
.
By default, pgBackRest configured to save data in local s3 storage (which could be run via running docker compose -f compose.s3.yml up
.
If you want to access to remote s3 storage, you should modify backup-manager/config/pgbackrest.conf
, postgres/config/postgresql.conf
and set proper address for your s3 storage there and add certificates for your s3 storage.
For accessing management service via UI interface you should go to http://0.0.0.0:3000
Also, you can access to management service via API. The API server runs on http://0.0.0.0:8000
by default.
GET /ping
- Check if the service is running
GET /backups
- List all available backups
POST /backup/full
- Create a full backupPOST /backup/incr
- Create an incremental backupPOST /backup/diff
- Create a differential backup
POST /restore/immediate
- Perform immediate recoveryPOST /restore/existing
- Recover from existing stanzaPOST /restore/time?timestamp={unix_timestamp}
- Perform point-in-time recovery
POST /database?database_name={name}
- Create a new databaseDELETE /database?database_name={name}
- Drop a databasePOST /database/run
- Execute a custom query
GET /schedule
- List all scheduled backupsPOST /schedule
- Add a new backup schedule{ "job_type": "incr", "hour": 4, "minute": 0 }
DELETE /schedule/{schedule_id}
- Delete a scheduled backup
- Creating a scheduled backup:
curl -X POST http://0.0.0.0:8000/schedule \
-H "Content-Type: application/json" \
-d '{"job_type":"incr","hour":4,"minute":0}'
- Creating a new database:
curl -X POST "http://0.0.0.0:8000/database?database_name=mydb"
- Performing point-in-time recovery:
curl -X POST "http://0.0.0.0:8000/restore/time?timestamp=1743344067"