Advanced database copy and migration tool - supports MongoDB, MySQL, PostgreSQL, Redis
Project description
db-wizard
Advanced database copy and migration tool with interactive wizard. Supports MongoDB, MySQL, PostgreSQL, and Redis.
Why?
- Copying databases between servers means remembering long
mongodump/mysqldump/pg_dumpcommands with connection strings - Shell aliases with plaintext passwords end up in bash history
- No progress tracking, no error handling, no saved configurations
- Repetitive tasks require typing the same commands every time
db-wizard fixes all of this with saved hosts, saved tasks, SSH tunnels, interactive wizard, and proper error handling.
Quick Start
python -m venv .venv
source .venv/bin/activate
pip install -e .
# Launch interactive wizard
dbw
Key Features
- Multi-database: MongoDB, MySQL, PostgreSQL, and Redis through a single interface
- Auto-detect engine: URI scheme determines the engine (
mongodb://,mysql://,postgres://,redis://) - Interactive wizard: Guided menu for all operations
- SSH tunnels: Built-in tunnel for hosts behind SSH (auto port-forward)
- Saved hosts: Store connection configs with optional SSH tunnel
- Saved tasks: Create and execute repeatable copy/backup/restore tasks
- Full automation:
-yflag for unattended cron jobs - Backup & restore: Complete backup/restore with compression to local, SSH, or FTP storage
- Password masking: Credentials never shown in UI output
- Progress tracking: Real-time feedback during operations
- Smart copy: MongoDB uses mongodump/mongorestore (10-100x faster) with Python fallback; MySQL uses mysqldump/mysql pipe
Usage
Interactive Mode (Recommended)
dbw
The wizard guides you through:
- Select/create saved hosts (MongoDB, MySQL, PostgreSQL, or Redis, with optional SSH tunnel)
- Choose database and tables/collections
- Copy options (drop target, backup before drop, verify)
- Save as reusable task
Saved Tasks
# List tasks
dbw --list-tasks
# Run task with confirmation
dbw --task daily_backup
# Run automated (for cron)
dbw --task daily_backup -y
Direct Command Line
# MongoDB copy
dbw -s mongodb://source-server -t mongodb://target-server \
--source-db myapp --drop-target -y
# MySQL copy
dbw -s mysql://user:pass@remote:3306/production \
-t mysql://root@localhost/production \
--source-db production --drop-target -y
Backup & Restore
# Backup to local directory
dbw --backup mongodb://localhost/myapp --backup-to /var/backups
# Backup to SSH storage
dbw --backup mongodb://localhost/production --backup-to ssh://backup@server:/backups
# Restore
dbw --restore /backups/2025_01_15-production.tar.gz --restore-to mongodb://localhost
CLI Commands
| Command | Alias |
|---|---|
db-wizard |
Full name |
dbw |
Primary short alias |
Main Options
| Option | Description |
|---|---|
-s, --source |
Source database URI (mongodb:// or mysql://) |
-t, --target |
Target database URI |
--source-db |
Source database name |
--target-db |
Target database name (defaults to source-db) |
--source-collection |
Specific collection/table (omit for all) |
--drop-target |
Drop target before copying |
-y, --yes |
Full automation without prompts |
--verify |
Verify integrity after copy (MongoDB) |
--force-python |
Force Python copy instead of mongodump (MongoDB) |
--list-tasks |
Show saved tasks |
--list-hosts |
Show saved hosts |
-c, --count |
Count rows when listing tasks/hosts (slow on remote) |
--task <name> |
Execute saved task |
--verify-connection |
Test connection to a URI |
--backup |
Backup database |
--backup-to |
Backup destination (path or ssh:// or ftp://) |
--restore |
Restore from backup file |
--restore-to |
Restore target URI |
SSH Tunnels
Hosts behind SSH can be reached automatically. When adding a host in the wizard:
- Enter the database URI (e.g.,
mysql://user:pass@localhost:3306/db) - Enable SSH tunnel
- Enter SSH hostname (from
~/.ssh/config) or fulluser@hostdetails
The tunnel opens automatically when you select the host, forwards a random local port, and closes when db-wizard exits.
Tunnel config is saved with the host:
{
"hosts": {
"production": {
"uri": "mysql://user:pass@localhost:3306/mydb",
"ssh_tunnel": "production-server"
}
}
}
Configuration
Settings are saved in ~/.db_wizard_settings.json (auto-migrated from ~/.mongo_wizard_settings.json).
File permissions are set to 600 (owner-only) because it contains credentials.
{
"hosts": {
"local_mongo": "mongodb://localhost:27017",
"local_mysql": "mysql://root@localhost:3306",
"remote_db": {
"uri": "mysql://user:pass@localhost:3306/db",
"ssh_tunnel": "myserver"
}
},
"tasks": {
"sync_staging": {
"source_uri": "mongodb://production:27017",
"target_uri": "mongodb://staging:27017",
"source_db": "app",
"target_db": "app",
"drop_target": true
}
},
"storages": {
"backup_server": {
"type": "ssh",
"host": "backup.server.com",
"user": "backup",
"port": 22,
"path": "/backups"
}
}
}
System Requirements
- Python 3.11+
- For MongoDB:
mongodump/mongorestore(install withbrew install mongodb-database-tools) - For MySQL:
mysqldump/mysqlCLI tools (install withbrew install mysql-client) - For PostgreSQL:
pg_dump/pg_restore/psqlCLI tools (install withbrew install postgresql) - For Redis:
redis-cli(install withbrew install redis)
The wizard checks requirements at startup and shows what's available.
Testing
# All unit tests (no database server needed)
pytest tests/ --ignore=tests/test_integration.py --ignore=tests/test_full_integration.py -v
# With coverage
pytest --cov=db_wizard --cov-report=html tests/
# Integration tests (requires MongoDB on localhost:27017)
pytest tests/test_full_integration.py -v
162 unit tests covering: engine abstraction, MongoDB engine, MySQL engine, SSH tunnels, settings migration, storage backends, formatting, utilities, bug fixes.
Architecture
db_wizard/
engine.py # DatabaseEngine ABC + EngineFactory
engines/
mongo.py # MongoEngine (pymongo + mongodump/mongorestore)
mysql.py # MySQLEngine (mysqldump/mysql CLI)
postgres.py # PostgresEngine (pg_dump/psql CLI)
redis.py # RedisEngine (redis-cli)
flows/ # Wizard interaction flows (copy, backup, etc.)
tunnel.py # SSH tunnel manager (auto port-forward)
wizard.py # Interactive wizard entrypoint (engine-agnostic)
cli.py # Click CLI (auto-detects engine from URI)
backup.py # Backup/restore manager
task_runner.py # Saved task executor
settings.py # JSON config manager (~/.db_wizard_settings.json)
storage.py # Storage backends (Local, SSH/SCP, FTP)
The engine abstraction (DatabaseEngine ABC) allows adding new database engines by implementing a single interface. The wizard, CLI, backup manager, and task runner are all engine-agnostic.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file db_wizard-2.3.2.tar.gz.
File metadata
- Download URL: db_wizard-2.3.2.tar.gz
- Upload date:
- Size: 86.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b11d56e86254d5784bdd3cdefb6cb8972e4a5d1db566fbf2ce026fb06738ad18
|
|
| MD5 |
e469cb81a1f3a1613d69f71da3c4a724
|
|
| BLAKE2b-256 |
7558a73006255972badae300d6f5091bc82a3f8c30d4ebe04535458270a626d4
|
Provenance
The following attestation bundles were made for db_wizard-2.3.2.tar.gz:
Publisher:
release.yml on sathia-musso/db-wizard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
db_wizard-2.3.2.tar.gz -
Subject digest:
b11d56e86254d5784bdd3cdefb6cb8972e4a5d1db566fbf2ce026fb06738ad18 - Sigstore transparency entry: 1516436863
- Sigstore integration time:
-
Permalink:
sathia-musso/db-wizard@5cbe8df739df154d268cfa161f42299e80bdf697 -
Branch / Tag:
refs/tags/v2.3.2 - Owner: https://github.com/sathia-musso
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5cbe8df739df154d268cfa161f42299e80bdf697 -
Trigger Event:
push
-
Statement type:
File details
Details for the file db_wizard-2.3.2-py3-none-any.whl.
File metadata
- Download URL: db_wizard-2.3.2-py3-none-any.whl
- Upload date:
- Size: 75.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
867ec485167042fc05eccfccf9d4216d1683a725d0d8d7796748a035e924b4f5
|
|
| MD5 |
0f32b53ec455f69287aefee42d3f4758
|
|
| BLAKE2b-256 |
271a78ff99ea49660e40763958099e1cc127a13a9af1f278a708cdd0e11b8fbd
|
Provenance
The following attestation bundles were made for db_wizard-2.3.2-py3-none-any.whl:
Publisher:
release.yml on sathia-musso/db-wizard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
db_wizard-2.3.2-py3-none-any.whl -
Subject digest:
867ec485167042fc05eccfccf9d4216d1683a725d0d8d7796748a035e924b4f5 - Sigstore transparency entry: 1516437214
- Sigstore integration time:
-
Permalink:
sathia-musso/db-wizard@5cbe8df739df154d268cfa161f42299e80bdf697 -
Branch / Tag:
refs/tags/v2.3.2 - Owner: https://github.com/sathia-musso
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5cbe8df739df154d268cfa161f42299e80bdf697 -
Trigger Event:
push
-
Statement type: