Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Docker images to backup and restore postgres

NotificationsYou must be signed in to change notification settings

ServiceStack/backup-postgres

Repository files navigation

A containerized PostgreSQL backup service that automatically creates database backups with configurable retention policies and optional S3/R2 cloud storage sync.

Features

  • 🔄Automated Backups: Configurable backup intervals (default: 24 hours)
  • 🗂️Retention Policies: Automatic cleanup of old backups (local and cloud)
  • ☁️Cloud Storage: Support for AWS S3 and Cloudflare R2
  • 🐳Container Ready: Works with Docker Compose and Kamal accessories
  • 📊Health Checks: Built-in health monitoring
  • 🔒Secure: Uses environment variables for credentials

Quick Start

Using Docker Compose

  1. Create a.env file with your database credentials:
POSTGRES_USER=myuserPOSTGRES_PASSWORD=mypasswordPOSTGRES_DB=mydatabase# Optional: S3/R2 configurationS3_BUCKET=my-backup-bucketS3_PREFIX=db-backupsAWS_ACCESS_KEY_ID=your-access-keyAWS_SECRET_ACCESS_KEY=your-secret-keyAWS_DEFAULT_REGION=us-east-1# For Cloudflare R2, also set:AWS_ENDPOINT_URL=https://your-account-id.r2.cloudflarestorage.com
  1. Use the providedcompose.yml:
docker compose up -d

Using Kamal Accessory

Add to yourconfig/deploy.yml:

accessories:postgres-backup:image:ghcr.io/servicestack/backup-postgres:latesthost:your-serverenv:clear:POSTGRES_HOST:postgresBACKUP_INTERVAL:"86400"# 24 hoursRETENTION_DAYS:"7"S3_BUCKET:"your-backup-bucket"S3_PREFIX:"db-backups"S3_RETENTION_DAYS:"30"secret:        -POSTGRES_USER        -POSTGRES_PASSWORD        -POSTGRES_DB        -AWS_ACCESS_KEY_ID        -AWS_SECRET_ACCESS_KEY        -AWS_DEFAULT_REGION        -AWS_ENDPOINT_URL# For R2volumes:      -"/opt/backups:/backups"depends_on:      -postgres

Configuration

Environment Variables

VariableRequiredDefaultDescription
POSTGRES_HOST-PostgreSQL server hostname
POSTGRES_USER-Database username
POSTGRES_PASSWORD-Database password
POSTGRES_DB-Database name
BACKUP_INTERVAL86400Backup interval in seconds
RETENTION_DAYS7Local backup retention in days
S3_BUCKET-S3/R2 bucket name
S3_PREFIXdb-backupsS3/R2 prefix/folder
S3_RETENTION_DAYS-Cloud backup retention in days
AWS_ACCESS_KEY_ID-AWS/R2 access key
AWS_SECRET_ACCESS_KEY-AWS/R2 secret key
AWS_DEFAULT_REGION-AWS region
AWS_ENDPOINT_URL-Custom endpoint (for R2)

Backup Schedule

  • Default: Every 24 hours (BACKUP_INTERVAL=86400)
  • Custom: SetBACKUP_INTERVAL to any value in seconds
  • Examples:
    • Every 6 hours:BACKUP_INTERVAL=21600
    • Every 12 hours:BACKUP_INTERVAL=43200
    • Every hour:BACKUP_INTERVAL=3600

Retention Policies

  • Local: Controlled byRETENTION_DAYS (default: 7 days)
  • Cloud: Controlled byS3_RETENTION_DAYS (optional)
  • Cleanup runs after each backup

Storage Options

Local Storage Only

Set only the PostgreSQL connection variables. Backups will be stored locally with the configured retention policy.

AWS S3

S3_BUCKET=my-backup-bucketAWS_ACCESS_KEY_ID=your-access-keyAWS_SECRET_ACCESS_KEY=your-secret-keyAWS_DEFAULT_REGION=us-east-1

Cloudflare R2

S3_BUCKET=my-backup-bucketAWS_ACCESS_KEY_ID=your-r2-access-keyAWS_SECRET_ACCESS_KEY=your-r2-secret-keyAWS_ENDPOINT_URL=https://your-account-id.r2.cloudflarestorage.com

Development

Local Development

Use the development compose file:

docker compose -f compose.dev.yml up -d

This builds the image locally instead of pulling from the registry.

Building the Image

docker build -t backup-postgres.

Monitoring

Health Checks

The container includes health checks that verify the backup service is running:

docker ps# Check health statusdocker logs postgres_backup# View logs

Logs

The service provides detailed logging with timestamps:

docker compose logs -f postgres_backup

Troubleshooting

Common Issues

  1. Connection Failed: Verify PostgreSQL credentials and network connectivity
  2. S3 Upload Failed: Check AWS credentials and bucket permissions
  3. Permission Denied: Ensure backup volume has proper write permissions

Debug Mode

Add verbose logging by checking container logs:

docker compose logs postgres_backup

License

MIT License - see LICENSE file for details.

About

Docker images to backup and restore postgres

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

[8]ページ先頭

©2009-2025 Movatter.jp