DBDock
Enterprise-grade PostgreSQL backup and restore. Beautiful CLI with real-time progress tracking.Quick Start
Features
- Beautiful CLI - Real-time progress bars, speed tracking, smart filtering
- Multiple Storage - Local, AWS S3, Cloudflare R2, Cloudinary
- Security - AES-256 encryption, Brotli compression
- Retention Policies - Automatic cleanup by count/age with safety nets
- Smart UX - Intelligent filtering for 100+ backups, clear error messages
- Alerts - Email (SMTP) and Slack notifications for backups (CLI & Programmatic)
- TypeScript Native - Full type safety for programmatic usage
- Automation - Cron schedules, auto-cleanup after backups
Installation
Global Installation (Recommended):CLI Commands
dbdock init
Interactive setup wizard that creates dbdock.config.json with:
- Database connection (host, port, credentials)
- Storage provider (Local, S3, R2, Cloudinary)
- Encryption/compression settings
- Email and Slack alerts (optional)
.gitignore to protect credentials.
npx dbdock backup
Creates database backup with real-time progress tracking:
--encrypt/--no-encrypt- Toggle encryption--compress/--no-compress- Toggle compression--encryption-key <key>- 64-char hex key (must be exactly 64 hexadecimal characters)--compression-level <1-11>- Compression level (default: 6)
custom(default) - PostgreSQL custom binary format (.sql)plain- Plain SQL text format (.sql)directory- Directory format (.dir)tar- Tar archive format (.tar)
npx dbdock restore
Interactive restore with smart filtering and multi-step progress:
- Show recent (last 10)
- Date range (24h, 7d, 30d, 90d, custom)
- Search by keyword/ID
npx dbdock list
View backups with smart filtering:
npx dbdock delete
Delete backups interactively or by key:
npx dbdock cleanup
Clean up old backups based on retention policy:
dbdock status
Quick view of all schedules and service status:
dbdock test
Validates database, storage, and email configuration.
dbdock schedule
Manage backup schedules in configuration:
- View current schedules with status
- Add new schedule with cron expression presets
- Remove or toggle (enable/disable) schedules
- Saves to
dbdock.config.json
- Every hour:
0 * * * * - Every day at midnight:
0 0 * * * - Every day at 2 AM:
0 2 * * * - Every week (Sunday):
0 0 * * 0 - Every month (1st):
0 0 1 * * - Custom cron expression
Configuration
After runningnpx dbdock init, a dbdock.config.json file is created:
Storage Providers
Local:s3:PutObject, s3:GetObject, s3:ListBucket, s3:DeleteObject
Cloudflare R2:
dbdock_backups/ folder with format: backup-YYYY-MM-DD-HH-MM-SS-BACKUPID.sql
Retention Policy
Automatic cleanup to prevent storage bloat from frequent backups:- Keeps most recent
minBackups(safety net, never deleted) - Deletes backups exceeding
maxBackupslimit (oldest first) - Deletes backups older than
maxAgeDays(respecting minBackups) - Runs automatically after each backup (if
runAfterBackup: true) - Manual cleanup:
npx dbdock cleanup
- Always preserves
minBackupsmost recent backups - Shows preview before deletion
- Detailed logging of what was deleted
- Error handling for failed deletions
Programmatic Usage
Use DBDock in your Node.js application to create backups programmatically. You don’t need to understand NestJS internals - DBDock provides a simple API that works with any Node.js backend.Basic Setup
First, install DBDock:dbdock.config.json configured (run npx dbdock init first). DBDock reads all configuration from this file automatically.
How It Works
DBDock uses a simple initialization pattern:- Call
createDBDock()to initialize DBDock (reads fromdbdock.config.json) - Get the
BackupServicefrom the returned context using.get(BackupService) - Use the service methods to create backups, list backups, etc.
createDBDock() as a factory function that sets up everything for you based on your config file.
Creating Backups
compress- Enable/disable compression (default: from config)encrypt- Enable/disable encryption (default: from config)format- Backup format:'custom'(default),'plain','directory','tar'type- Backup type:'full'(default),'schema','data'
Listing Backups
Getting Backup Metadata
npx dbdock restore). Programmatic restore will be available in a future release.
Scheduling Backups
DBDock doesn’t include a built-in scheduler (to keep the package lightweight), but it’s easy to schedule backups usingnode-cron.
First, install node-cron:
scheduler.ts):
dbdock schedule command manages configuration for external schedulers but does not run a daemon itself. Using node-cron as shown above is the recommended way to run scheduled backups programmatically.
Requirements
- Node.js 18 or higher
- PostgreSQL 12+
- PostgreSQL client tools (
pg_dump,pg_restore,psql)
Troubleshooting
Runnpx dbdock test to verify your configuration.
Common Issues
pg_dump not found:- Verify
host,port,username,password,databasein config - Test connection:
psql -h HOST -p PORT -U USERNAME -d DATABASE - Check PostgreSQL server is running
- Verify network/firewall allows connection
- Verify credentials are correct
- Ensure IAM user has permissions:
s3:PutObject,s3:GetObject,s3:ListBucket,s3:DeleteObject - Check bucket name and region
- Verify API token is correct
- Check endpoint URL format:
https://ACCOUNT_ID.r2.cloudflarestorage.com - Ensure bucket exists and is accessible
- Verify R2 credentials have read/write permissions
- Verify cloud name, API key, and secret are correct
- Check your Cloudinary account is active
- Ensure API credentials have media library access
- Ensure backups are in
dbdock_backups/folder - Verify backup files are named with
.sqlextension - Check endpoint configuration matches R2 account ID
- Local: Check files exist in configured path
- S3/R2: Verify files are in
dbdock_backups/folder - Cloudinary: Check Media Library for
dbdock_backupsfolder - Ensure files match pattern:
backup-*.sql
Documentation
📚 Full Documentation - Comprehensive guides, API reference, and examplesSupport
- 💬 Discussions - Ask questions and share ideas
- 🐛 Issues - Report bugs and request features
