Backup Postgresql to Minio
cp .env.example .envMINIO_ACCESS_KEY=12345678
MINIO_SECRET_KEY=12345678
MINIO_BUCKET=minio
MINIO_SERVER=http://127.0.0.1:9000
docker-compose up -dversion: '3'
services:
pg2minio:
container_name: pg2minio
image: anhnmt/backup-pg2minio:latest
build:
context: .
dockerfile: ./Dockerfile
env_file:
- .env
network_mode: host
MINIO_ACCESS_KEY - Your Minio access key.
MINIO_SECRET_KEY - Your Minio access key.
MINIO_BUCKET - Your Minio bucket.
MINIO_SERVER - Your Minio server
POSTGRES_HOST - Hostname of the PostgreSQL database to backup, alternatively this container can be linked to the container with the name postgres.
ACTION - Action to perform: backup (default) or restore.
SCHEDULE - Cron schedule to run periodic backups.
POSTGRES_PASSWORD - Password for the PostgreSQL user, if you are using a database on the same machine this isn't usually needed.
POSTGRES_PORT - Port of the PostgreSQL database, uses the default 5432.
POSTGRES_EXTRA_OPTS - Extra arguments to pass to the pg_dump command.
POSTGRES_DATABASE - Name of the PostgreSQL database to backup.
POSTGRES_USER - PostgreSQL user, with priviledges to dump the database.
POSTGRES_PRERUN - Check connection before executing.
POSTGRES_FORMAT - Dump format: custom (default), directory, plain, tar. Use custom or directory for TimescaleDB.
MINIO_API_VERSION - you can change with S3v4 or S3v2.
MINIO_CLEAN - Assign a value to activate, default is 0. For example: 7d, 14d, 1m, 30s
MINIO_BACKUP_DIR - Allows you to change the path in the bucket. e.g. abc/def (without / at the beginning and end)
MINIO_INSECURE - Disables TLS/SSL certificate verification.
MINIO_DEBUG - Enables verbose output to the console.
MINIO_PRERUN - Check connection before executing.
TELEGRAM_ENABLED - Set true to enable. Default is false
TELEGRAM_CHAT_ID - Chat ID for example -40054422
TELEGRAM_TOKEN - Telegram bot token for example 610864305:AAGw2BVSPYPjcc8940bswQTRUZIssSFJA, without bot at the beginning
METRICS_ENABLED - Set true to enable metrics collection. Default is false.
METRICS_NAMESPACE - Namespace for the metrics. Default is empty.
METRICS_SUBSYSTEM - Subsystem for the metrics. Default is empty.
METRICS_PORT - Port for the metrics endpoint. Default is 8080.
METRICS_PATH - Path for the metrics endpoint. Default is /metrics.
HTTP_TRIGGER_ENABLED - Set true to enable HTTP trigger server for manual backup. Default is false.
HTTP_TRIGGER_PORT - Port for HTTP trigger server. Default is 8081.
HTTP_TRIGGER_PATH - Path for trigger endpoint. Default is /trigger.
To restore a database, set ACTION=restore and configure:
ACTION=restore - RequiredRESTORE_SOURCE_PATH - Path to backup file in Minio (e.g., bucket/database/backup_2024-01-15.sql.gz)RESTORE_TARGET_DB - Target database name (optional, defaults to source database)Example:
ACTION=restore
RESTORE_SOURCE_PATH=mybucket/mydb/mydb_2024-01-15T10:00:00Z.sql.gz
RESTORE_TARGET_DB=restored_db
To enable manual backup trigger via HTTP:
HTTP_TRIGGER_ENABLED=true
HTTP_TRIGGER_PORT=8081
HTTP_TRIGGER_PATH=/trigger
Trigger a backup:
curl -X POST http://localhost:8081/trigger
Check health:
curl http://localhost:8081/health
Content type
Image
Digest
sha256:ddf1b13dc…
Size
128.9 MB
Last updated
6 months ago
docker pull anhnmt/backup-pg2minio