A generic database backup application capable of backing up PostgreSQL, MySQL, MongoDB, and Redis databases. Features background processing, webhook notifications, automatic daily cleanup, cloud storage integration (Cloudflare R2), and backup management with MongoDB.
pending, generating, completed, and failed states.pg_dump, mysqldump, mongodump, redis-cli) if running locally without Docker.MONGO_URI - MongoDB connection string (e.g., mongodb://localhost:27017)MONGO_DATABASE - MongoDB database name (default: db-backup)R2_ENDPOINT - Cloudflare R2 endpoint URLR2_ACCESS_KEY_ID - R2 access keyR2_SECRET_ACCESS_KEY - R2 secret access keyR2_BUCKET_NAME - R2 bucket nameR2_REGION - R2 region (default: auto)Clone the repository:
git clone https://github.com/ariefsn/db-backup.git
cd db-backup
Set environment variables:
export MONGO_URI="mongodb://localhost:27017"
export MONGO_DATABASE="db-backup"
export R2_ENDPOINT="https://your-account.r2.cloudflarestorage.com"
export R2_ACCESS_KEY_ID="your-access-key"
export R2_SECRET_ACCESS_KEY="your-secret-key"
export R2_BUCKET_NAME="db-backups"
Run the server:
make run
# OR
go run cmd/server/main.go
Access API:
Pull the image from Docker Hub:
docker pull ariefsn/db-backup:latest
docker run --rm -p 8080:8080 \
-e MONGO_URI="mongodb://host.docker.internal:27017" \
-e R2_ENDPOINT="https://your-account.r2.cloudflarestorage.com" \
-e R2_ACCESS_KEY_ID="your-key" \
-e R2_SECRET_ACCESS_KEY="your-secret" \
-e R2_BUCKET_NAME="db-backups" \
ariefsn/db-backup:latest
To run both the backend and web interface:
docker compose up -d
This will run:
POST /backup
{
"type": "postgre",
"name": "My Prod DB",
"host": "postgres-host",
"port": "5432",
"username": "user",
"password": "password",
"database": "mydb",
"connectionUri": "postgresql://user:pass@host:5432/mydb",
"webhookUrl": "https://your-webhook.com/callback",
"cronExpression": "0 0 * * *",
"isActive": true
}
Note
You can use either the individual host/port/user fields OR a `connectionUri`. If `connectionUri` is provided, it takes precedence.
Supported Types: postgre, mysql, mongo, redis
Response: 202 Accepted
GET /databases - List all saved database configurations
POST /databases - Create a new database configuration
GET /databases/{id} - Get a single database configuration
PUT /databases/{id} - Update a database configuration
DELETE /databases/{id} - Delete a database configuration
POST /databases/{id}/backup - Manually trigger backup for a saved database
GET /backups?page=1&limit=10&statuses=completed,failed
Returns paginated list of backup metadata with optional status filtering.
Query Parameters:
page - Page number (default: 1)limit - Items per page (default: 10, max: 100)statuses - Comma-separated status values: pending, generating, completed, failedResponse:
{
"backups": [
{
"id": "507f1f77bcf86cd799439011",
"type": "postgre",
"objectKey": "backups/postgre/20231225-120000_mydb.sql",
"filePath": "/backups/mydb_20231225_120000.sql",
"fileSize": 1024000,
"timestamp": "2023-12-25T12:00:00Z",
"status": "completed",
"host": "postgres-host",
"database": "mydb"
}
],
"total": 42,
"page": 1,
"limit": 10
}
Status Filtering Examples:
# Get only completed backups
GET /backups?statuses=completed
# Get failed and pending backups
GET /backups?statuses=failed,pending
# Get backups currently being generated
GET /backups?statuses=generating
GET /backups/{id}
Retrieve a single backup by ID.
Response:
{
"id": "507f1f77bcf86cd799439011",
"type": "postgre",
"objectKey": "backups/postgre/20231225-120000_mydb.sql",
"filePath": "/backups/mydb_20231225_120000.sql",
"fileSize": 1024000,
"timestamp": "2023-12-25T12:00:00Z",
"status": "completed",
"host": "postgres-host",
"database": "mydb"
}
DELETE /backups/{id}
Deletes backup from both MongoDB and R2 storage.
Response: 200 OK
When a backup completes, the webhook receives:
{
"success": true,
"filePath": "/backups/mydb_20231225_120000.sql",
"objectKey": "backups/postgre/20231225-120000_mydb.sql",
"timestamp": "2023-12-25T12:00:00Z",
"metadata": {
"database_type": "postgre",
"host": "postgres-host",
"database": "mydb",
"file_size": "1024000",
"storage": "r2"
}
}
make build: Build the binary.make run: Run the application.make docker-build: Build local Docker image.make docker-push: Build and push multi-platform Docker image.make swagger: Regenerate Swagger documentation.MIT
Content type
Image
Digest
sha256:8ef2c580a…
Size
75.6 MB
Last updated
21 days ago
docker pull ariefsn/db-backup