DBDock
Stop writing backup scripts. Stop losing sleep over database migrations. DBDock handles PostgreSQL backups, restores, database copies, and cross-database migrations between MongoDB and PostgreSQL in one command.The Problem
Every time you need to backup a database, copy it to staging, or restore before a migration — it’s the same boring steps. Connect, dump, upload, move files around, remember the right flags. It’s not hard. It’s just repetitive. And repetitive stuff should be one command.The Fix
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, or full URL via
DBDOCK_DB_URL), 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
- Cross-Database - MongoDB ↔ PostgreSQL migration with schema mapping and dry run
Installation
Global Installation (Recommended):CLI Commands
dbdock init — Set up in 30 seconds
Run once. It walks you through everything interactively:
- Config (safe stuff) goes to
dbdock.config.json— commit this - Secrets go to
.env— never committed,.gitignoreupdated automatically
DBDOCK_DB_URL (or DATABASE_URL) and other env vars and DBDock will use env-only configuration.
dbdock migrate-config — Fix legacy configs
dbdock.config.json from an older version? This extracts them to .env, cleans up your config, and updates .gitignore. One command, done.
npx dbdock backup — One command, full backup
--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
- Run
npx dbdock restore - Select a backup
- Choose “New Database Instance (Migrate)”
- Enter connection details for the target database
npx dbdock copydb — Copy a database with just two URLs
This is the one people love. No config files. No setup. Just paste two PostgreSQL URLs:
pg_dump directly into pg_restore — no temp files, no waiting.
Options: --schema-only (tables, indexes, constraints — no data), --data-only, --verbose
Environment consolidation:
npx dbdock list — See all your backups
npx dbdock delete — Remove backups
npx dbdock cleanup — Auto-clean old backups
dbdock status — Check schedules and service health
dbdock schedule — Manage cron schedules
dbdock test — Verify everything works
Cross-Database Migration (MongoDB ↔ PostgreSQL)
Move data between MongoDB and PostgreSQL without throwaway scripts. DBDock analyzes the source, proposes a schema mapping, lets you review it, and handles the transfer.--dry-run), incremental sync (--incremental --since <date>), and export/import config (--export-config, --config). Failed rows go to _migration_errors; nothing executes without your confirmation. See the package README or CLI for full options.
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), or env vars - Sensitive secrets → Environment variables (e.g.
DBDOCK_DB_URL,DBDOCK_DB_PASSWORD, storage keys — 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. You can use a full database URL for env-only config (nodbdock.config.json needed):
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
Backups pile up fast. Retention handles it automatically:- 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
Don’t just use the CLI — drop DBDock into your Node.js app and trigger backups from code. Works with any backend (Express, Fastify, NestJS, whatever). You don’t need to understand NestJS internals; DBDock provides a simple API.Basic Setup
First, install DBDock:dbdock.config.json (run npx dbdock init) or configure entirely via env vars (DBDOCK_DB_URL or DATABASE_URL plus storage and other env vars). DBDock reads from config file and/or environment automatically.
How It Works
DBDock uses a simple initialization pattern:- Call
createDBDock()to initialize DBDock (reads fromdbdock.config.jsonand/or env vars) - 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 from your config and env vars.
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 is coming.
Schedule Backups with node-cron
DBDock stays lightweight — no built-in daemon. Usenode-cron to schedule:
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
First step, always:Common Issues
pg_dump not found:- Double-check
host,port,username,password,databasein config (or useDBDOCK_DB_URL/DATABASE_URL) - Test manually:
psql -h HOST -p PORT -U USERNAME -d DATABASE - Make sure the PostgreSQL server is actually running
- Check firewalls / security groups if it’s a remote database
s3:PutObject, s3:GetObject, s3:ListBucket, s3:DeleteObject.
R2: Check endpoint format (https://ACCOUNT_ID.r2.cloudflarestorage.com), verify API token and bucket exist.
Cloudinary: Verify cloud name, API key, API secret. Make sure the account is active.
Encryption key issues: Key must be exactly 64 hex characters. Generate a valid one:
- Local: Check the configured path has files
- S3/R2: Files should be in
dbdock_backups/folder - Cloudinary: Check Media Library for
dbdock_backupsfolder - Files should match:
backup-*.sql
Documentation
📚 Full Documentation - Comprehensive guides, API reference, and examplesSupport
- 💬 Discussions - Ask questions and share ideas
- 🐛 Issues - Report bugs and request features
