A comprehensive Docker-based backup and restore solution for PostgreSQL and MySQL databases with automated scheduling, retention policies, S3 integration, and a web UI.
- Multi-Database Support: Works with both PostgreSQL and MySQL
- Automated Scheduling: Cron-based scheduling for hourly, daily, weekly, and monthly backups
- Intelligent Retention: Hierarchical retention policies that automatically clean up old backups
- S3 Integration: Automatic upload to S3 with support for downloading and restoring from S3
- Web UI: Vue-based interface for managing backups, viewing logs, and performing restores
- SQLite Logging: Complete backup history and logs stored in SQLite
- Docker Ready: Fully containerized with Docker and Docker Compose support
- Backend: Bun + TypeScript + Hono
- Frontend: Vue 3 + TypeScript + Vite
- Database: Bun's built-in SQLite
- Backup Tools:
pg_dump/psqlfor PostgreSQL,mysqldump/mysqlfor MySQL - Cloud Storage: AWS S3 via official SDK
- Scheduler: node-cron
Copy the example configuration and customize it:
cp config.example.json config.jsonEdit config.json with your database and S3 credentials:
{
"database": {
"type": "postgresql",
"host": "postgres",
"port": 5432,
"username": "postgres",
"password": "password",
"database": "mydb"
},
"backup": {
"localPath": "/backups",
"schedules": {
"hourly": {
"cron": "0 * * * *",
"enabled": true,
"retention": {
"count": 6,
"unit": "hours"
}
},
"daily": {
"cron": "0 2 * * *",
"enabled": true,
"retention": {
"count": 7,
"unit": "days"
}
},
"weekly": {
"cron": "0 3 * * 0",
"enabled": true,
"retention": {
"count": 4,
"unit": "weeks"
}
},
"monthly": {
"cron": "0 4 1 * *",
"enabled": true,
"retention": {
"count": 12,
"unit": "months"
}
}
}
},
"s3": {
"enabled": true,
"bucket": "my-backup-bucket",
"region": "us-east-1",
"accessKeyId": "YOUR_ACCESS_KEY",
"secretAccessKey": "YOUR_SECRET_KEY",
"prefix": "database-backups/"
},
"server": {
"port": 3000,
"host": "0.0.0.0"
}
}The easiest way to get started is with Docker Compose, which includes example PostgreSQL and MySQL databases:
docker-compose up -dThis will start:
- PostgreSQL database on port 5432
- MySQL database on port 3306
- Backup service with web UI on port 3000
Access the web UI at: http://localhost:3000
If you prefer to run the backup service standalone:
# Install dependencies
bun install
# Build frontend
cd frontend
bun install
bun run build
cd ..
# Run the service
bun run src/index.tsThe retention system uses a hierarchical approach:
- Hourly backups: Keep the last 6 hours
- Daily backups: Keep the last 7 days
- Weekly backups: Keep the last 4 weeks
- Monthly backups: Keep the last 12 months
When a higher-level backup is created, it triggers cleanup of lower-level backups:
- When a daily backup runs → deletes all hourly backups before it
- When a weekly backup runs → deletes all hourly and daily backups before it
- When a monthly backup runs → deletes all hourly, daily, and weekly backups before it
This ensures efficient storage usage while maintaining appropriate recovery points.
The web interface provides:
- Dashboard: View all backups with status, size, and timestamps
- Manual Backups: Trigger backups on-demand
- Restore: Restore from local or S3 backups
- Log Viewer: Inspect detailed logs for each backup
- Real-time Status: See backup job status and history
GET /api/backups- List all backupsGET /api/backups/type/:type- List backups by typeGET /api/backups/:id- Get single backupGET /api/backups/:id/logs- Get backup logsPOST /api/backups/run/:type- Trigger manual backupDELETE /api/backups/:id- Delete backupPOST /api/backups/:id/restore- Restore from local backupPOST /api/backups/:id/restore-s3- Restore from S3 backup
GET /api/s3/backups- List S3 backupsPOST /api/s3/download- Download backup from S3
GET /api/config- Get sanitized configurationGET /api/health- Health check
0 * * * * # Every hour at minute 0
0 2 * * * # Every day at 2:00 AM
0 3 * * 0 # Every Sunday at 3:00 AM
0 4 1 * * # First day of every month at 4:00 AM
*/30 * * * * # Every 30 minutes
0 */6 * * * # Every 6 hours
The service can be configured via environment variables or config.json. Mount your config file:
volumes:
- ./config.json:/app/config.json
- ./backups:/backups
- ./backups.db:/app/backups.dbThe backup service needs network access to your database. In Docker Compose, use a shared network:
networks:
- backup-network- Credentials: Never commit
config.jsonwith real credentials - S3 Access: Use IAM roles with minimal required permissions
- Database Access: Use read-only users when possible for backups
- Network: Restrict backup service access in production environments
- Backups: Encrypt sensitive backups at rest and in transit
- Test Restores: Regularly test backup restores to ensure they work
- Monitor Space: Monitor local disk space for backup storage
- S3 Lifecycle: Configure S3 lifecycle rules for long-term archival
- Multiple Regions: Consider cross-region S3 replication for disaster recovery
- Retention Tuning: Adjust retention policies based on RPO/RTO requirements
Check the logs in the web UI. Common issues:
- Database connection failed: Verify host, port, credentials
- Disk space: Ensure sufficient space in
/backups - Permissions: Verify the user has database dump permissions
- Verify S3 credentials and bucket permissions
- Check network connectivity to S3
- Ensure bucket exists and region is correct
# View logs
docker-compose logs backup
# Restart service
docker-compose restart backup
# Check health
docker-compose ps# Backend
bun install
bun run dev
# Frontend (separate terminal)
cd frontend
bun install
bun run devFrontend will be available at http://localhost:5173 with API proxy to http://localhost:3000
.
├── src/ # Backend TypeScript code
│ ├── index.ts # Main entry point
│ ├── api.ts # Hono API routes
│ ├── backup.ts # Backup engine
│ ├── restore.ts # Restore engine
│ ├── retention.ts # Retention policy engine
│ ├── scheduler.ts # Cron scheduler
│ ├── database.ts # SQLite database
│ ├── s3.ts # S3 integration
│ ├── config.ts # Configuration loader
│ └── types.ts # TypeScript types
├── frontend/ # Vue frontend
│ ├── src/
│ │ ├── App.vue # Main app component
│ │ ├── views/ # Page components
│ │ ├── api.ts # API client
│ │ └── types.ts # TypeScript types
│ └── vite.config.ts
├── Dockerfile
├── docker-compose.yml
└── config.example.json
MIT
Contributions are welcome! Please feel free to submit a Pull Request.