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 First - Hybrid config (env vars for secrets), AES-256 encryption, credential masking, .pgpass support
- 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
- Migration Tool - One command to migrate legacy configs to secure env vars
Installation
Global Installation (Recommended):CLI Commands
dbdock init
Interactive setup wizard that creates secure configuration:
- Database connection (host, port, credentials)
- Storage provider (Local, S3, R2, Cloudinary)
- Encryption/compression settings
- Email and Slack alerts (optional)
- Saves non-sensitive config to
dbdock.config.json(safe for git) - Saves secrets to
.env(automatically gitignored) - Auto-updates
.gitignoreto exclude sensitive files
dbdock migrate-config
Migrate existing configurations with embedded secrets:
dbdock.config.json, creates .env, and updates your config to use environment variables.
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
- Run
npx dbdock restore - Select a backup
- Choose βNew Database Instance (Migrate)β
- Enter connection details for the target database
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
Security Best Practices
Secure Configuration Management
DBDock uses a hybrid configuration approach to keep your secrets safe:- Non-sensitive settings β
dbdock.config.json(safe for version control) - Sensitive secrets β Environment variables (NEVER commit to git)
npx dbdock init, DBDock automatically:
- Saves credentials to
.env(not committed) - Saves only non-sensitive config to
dbdock.config.json - Updates
.gitignoreto exclude.env
.env and .env.local files (with .env.local taking priority for local overrides). You can use either file depending on your workflow.
Environment Variables
Set these environment variables for secure credential management:Migration from Legacy Config
If you have an existing configuration with secrets indbdock.config.json:
- Extract all secrets from your config file
- Create/update
.envwith the secrets - Remove secrets from
dbdock.config.json - Update
.gitignoreautomatically
Using .pgpass for PostgreSQL
For enhanced security, use.pgpass instead of environment variables:
.pgpass when available, which is more secure than PGPASSWORD environment variables.
Security Features
- Automatic credential masking - All passwords and keys are masked in logs
- File permission checking - Warns about insecure config file permissions
- Encryption at rest - AES-256-GCM encryption for backups
- Strict mode - Optional enforcement of env-only secrets (
DBDOCK_STRICT_MODE=true)
Configuration
After runningnpx dbdock init, a dbdock.config.json file is created (without sensitive data):
user, pass) and storage secrets are set via environment variables for security.
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
Links
- π¦ npm Package
- π Documentation
- π» GitHub Repository
