
如果你使用 DeepSeek、元宝 AI、Copilot、ChatGPT 等 AI 工具,协助配置轩辕镜像、编写 docker pull 命令、修改 Docker Compose 镜像地址、配置镜像加速、排查镜像拉取失败、分析报错日志等问题,请先让 AI 阅读并遵守轩辕镜像的规则文档。
只需在 AI 对话中先发送下面这句话即可:
请先完整阅读并严格遵守以下文档中的全部规则与要求:
https://xuanyuan.cloud/agents.md
在未充分阅读并理解该文档前,不要生成任何命令、配置、修改建议、故障排查方案或技术回答。后续所有输出都必须严格以该文档中的规范为最高优先级执行。查看 agents.md 用法指南与完整示范。国内用户首推 元宝 AI、DeepSeek 的深度思考模式,不推荐豆包 AI;Cursor 等编辑器可在对话 @ 该链接,或加入 User Rules。 若 AI 无法访问外链,可 打开说明文档 复制全文粘贴。文档会随站点更新,复制内容可能过期,建议定期检查。
https://img.shields.io/badge/docker-ready-blue.svg]([] https://img.shields.io/badge/TypeScript-007ACC?logo=typescript&logoColor=white](https://www.typescriptlang.org/) https://img.shields.io/badge/Fastify-000000?logo=fastify&logoColor=white]([]
A modern REST API for PostgreSQL database backups to S3-compatible storage (AWS S3, MinIO, DigitalOcean Spaces, etc.) with API key authentication, built with TypeScript and Fastify.
Clone the repository
bashgit clone https://github.com/danielgtmn/docker-pg-backup.git cd docker-pg-backup
Configure environment
bashcp env.example .env # Edit .env with your storage configuration
Start the API server
bashdocker-compose up -d
Access the API
This project uses GitHub Actions for automated CI/CD. Docker images are automatically built and published to the GitHub Container Registry (ghcr.io).
v* tags creates versioned releasesbash# Latest version from main branch docker pull ghcr.io/danielgtmn/docker-pg-backup:latest # Specific version docker pull ghcr.io/danielgtmn/docker-pg-backup:v1.0.0 # Commit-based version docker pull ghcr.io/danielgtmn/docker-pg-backup:main-<commit-sha>
Images are built for both linux/amd64 and linux/arm64 architectures.
Create a .env file based on env.example:
bash# API Configuration NODE_ENV=production PORT=3000 HOST=0.0.0.0 # API Authentication (required) API_KEY=your-secure-api-key-here # PostgreSQL Connection String (optional - provided per backup request) # DATABASE_URL=postgresql://username:password@hostname:port/database # ================= AWS S3 Storage ================= S3_BUCKET=my-backup-bucket S3_PREFIX=postgres-backups AWS_REGION=us-east-1 AWS_ACCESS_KEY_ID=your-access-key AWS_SECRET_ACCESS_KEY=your-secret-key # ================= MinIO / Custom S3 ================= # S3_ENDPOINT=https://minio.example.com:9000 # S3_BUCKET=my-backup-bucket # S3_PREFIX=postgres-backups # AWS_ACCESS_KEY_ID=minio-access-key # AWS_SECRET_ACCESS_KEY=minio-secret-key # ================= DigitalOcean Spaces ================= # S3_ENDPOINT=https://fra1.digitaloceanspaces.com # S3_BUCKET=my-spaces-bucket # S3_PREFIX=postgres-backups # AWS_REGION=fra1 # AWS_ACCESS_KEY_ID=spaces-access-key # AWS_SECRET_ACCESS_KEY=spaces-secret-key
This API supports various S3-compatible storage services:
bashS3_ENDPOINT= # (optional, uses AWS default) S3_BUCKET=my-bucket AWS_REGION=us-east-1 AWS_ACCESS_KEY_ID=... AWS_SECRET_ACCESS_KEY=...
bashS3_ENDPOINT=https://minio.example.com:9000 S3_BUCKET=my-bucket AWS_ACCESS_KEY_ID=minio-user AWS_SECRET_ACCESS_KEY=minio-password
bashS3_ENDPOINT=https://fra1.digitaloceanspaces.com S3_BUCKET=my-spaces-bucket AWS_REGION=fra1 AWS_ACCESS_KEY_ID=spaces-key AWS_SECRET_ACCESS_KEY=spaces-secret
S3_ENDPOINT=https://us-east-1.linodeobjects.comS3_ENDPOINT=https://s3.wasabisys.comS3_ENDPOINT=https://s3.us-west-002.backblazeb2.comThis API uses semantic versioning for all endpoints to ensure backward compatibility and smooth upgrades.
v1 (stable)/v{number}/api/{endpoint}/api/* routes are automatically redirected to /v1/api/*| Version | Status | Release Date | Deprecation Date | Sunset Date |
|---|---|---|---|---|
v1 | Current | 2024-01-01 | - | - |
Note: All API endpoints require authentication via API key in the
Authorizationheader.
Version 1 (Current)
http# Create Backup POST /v1/api/backup Authorization: Bearer your-api-key-here Content-Type: application/json { "databaseUrl": "postgresql://user:pass@host:5432/mydb", "backupName": "my-backup.sql.gz" // optional } # List Backups GET /v1/api/backups?limit=10&prefix=my-backups # Health Check GET /v1/api/health # Configuration Info GET /v1/api/config
Legacy Compatibility (Automatic Redirect)
The following legacy routes are automatically redirected to versioned endpoints:
/api/backup → /v1/api/backup/api/backups → /v1/api/backups/api/health → /v1/api/health/api/config → /v1/api/configVisit http://localhost:3000/docs for the complete interactive Swagger documentation with:
Upgrading from Legacy API
If you're currently using the legacy /api/* endpoints:
/v1/api/*) for better performanceExample Migration
Before (Legacy):
bashcurl -X POST http://localhost:3000/api/backup \ -H "Authorization: Bearer your-api-key" \ -H "Content-Type: application/json" \ -d '{"databaseUrl": "postgresql://..."}'
After (Versioned):
bashcurl -X POST http://localhost:3000/v1/api/backup \ -H "Authorization: Bearer your-api-key" \ -H "Content-Type: application/json" \ -d '{"databaseUrl": "postgresql://..."}'
X-API-Version, X-Deprecation-Warning)API responses include version information in headers:
httpX-API-Version: v1 X-API-Current-Version: v1 X-API-Supported-Versions: v1
Deprecated endpoints include additional headers:
httpX-Deprecation-Warning: "API version v1 is deprecated. Please migrate to v2" X-Sunset-Date: "2025-01-01T00:00:00Z"
Required headers:
Authorization: Bearer <your-api-key>Content-Type: application/jsonRequired fields:
databaseUrl: PostgreSQL connection string (must start with postgresql://)Optional fields:
backupName: Custom backup filename (defaults to timestamp)Response:
json{ "success": true, "data": { "backupPath": "s3://my-backup-bucket/postgres-backups/20241201_120000_backup.sql.gz", "fileSize": 1048576, "duration": 2500, "timestamp": "2024-12-01T12:00:00.000Z" } }
Versioned Endpoint (Recommended)
httpGET /v1/api/backups?limit=10&prefix=my-backups
Legacy Endpoint (Auto-redirects to versioned)
httpGET /api/backups?limit=10&prefix=my-backups
Versioned Endpoint (Recommended)
httpGET /v1/api/health
Legacy Endpoint (Auto-redirects to versioned)
httpGET /api/health
Versioned Endpoint (Recommended)
httpGET /v1/api/config Authorization: Bearer your-api-key-here
Legacy Endpoint (Auto-redirects to versioned)
httpGET /api/config Authorization: Bearer your-api-key-here
bash# Build and run docker-compose up --build # Run in background docker-compose up -d # View logs docker-compose logs -f postgres-backup-api # Stop docker-compose down
bash# Build for production docker build -t postgres-backup-api . # Run with .env file (recommended) docker run -d \ --name postgres-backup-api \ --env-file .env \ -p 3000:3000 \ postgres-backup-api # Or run with manual environment variables docker run -d \ --name postgres-backup-api \ -p 3000:3000 \ -e S3_BUCKET="my-bucket" \ -e AWS_ACCESS_KEY_ID="..." \ -e AWS_SECRET_ACCESS_KEY="..." \ -e API_KEY="your-secure-api-key" \ postgres-backup-api
bash# Install dependencies pnpm install # Development mode with hot reload pnpm dev # Build for production pnpm build # Run tests pnpm test # Lint code pnpm lint
When running, visit http://localhost:3000/docs for interactive API documentation with:
| Storage | Configuration | Verification | Notes |
|---|---|---|---|
| AWS S3 | S3_BUCKET, AWS_ACCESS_KEY_ID | ✅ HeadObject | Most common choice |
| Google Cloud Storage | GCS_BUCKET, GOOGLE_APPLICATION_CREDENTIALS | ✅ File exists | Requires service account |
| Azure Blob Storage | AZURE_ACCOUNT, AZURE_CONTAINER | ✅ Blob exists | Requires storage account |
| Local Filesystem | BACKUP_DIR | ✅ File exists | For development/testing |
The API returns structured error responses:
json{ "success": false, "error": "Validation failed", "details": ["databaseUrl is required"] }
Common HTTP status codes:
200 - Success400 - Bad Request (validation errors)500 - Internal Server Error/v1/api/health (versioned) or /api/health (legacy, auto-redirects)MIT License - see LICENSE file for details.
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
来自真实用户的反馈,见证轩辕镜像的优质服务