Sync remote MySQL databases to local Dbngin instances over SSH with streaming pipes.
A lightweight terminal tool designed for macOS users who use Dbngin to manage their local databases. This script allows you to securely sync a remote MySQL database to your local environment over SSH using efficient streaming pipes.
- TUI Driven: Interactive selection for remote databases and local Dbngin instances powered by
fzf(fuzzy search, keyboard navigation). - Zero Dependencies: Pure Bash script, no Node.js or Python required (just
fzfandssh). - Auto-Config: Saves your credentials in a
.envfile for faster subsequent runs. - Efficient Syncing: Streams
mysqldumpdirectly intomysqlvia SSH pipes (no giant temp files). - Dbngin Aware: Automatically detects your Dbngin MySQL binaries and lets you choose a version when multiple exist.
- Automatic Backups: Offers to create a compressed backup before overwriting an existing local database.
- SSH Multiplexing: Reuses a single SSH connection for the entire session (faster, fewer auth prompts).
- Error Diagnostics: Captures and displays real error output to help troubleshoot failures.
- Graceful Interrupts: Safe Ctrl+C handling with automatic cleanup.
- macOS (Apple Silicon or Intel).
- Dbngin installed and running.
- fzf installed (
brew install fzf). - SSH access to your remote server.
- MySQL/MariaDB running on the remote server.
- Clone or download this repository.
- Ensure the script is executable:
chmod +x sync-db.sh
Run the script from your terminal:
./sync-db.shThe script will:
- Ask for your SSH and database credentials (if not already in
.env). - Test the SSH connection and establish a multiplexed session.
- List all databases on your remote server.
- Let you choose which database to sync (fuzzy-searchable via
fzf). - Let you specify the local database name (defaults to remote name).
- Detect Dbngin MySQL binaries and let you pick one if multiple exist.
- Show a summary and ask for confirmation.
- If the target exists: warn you, offer to overwrite, and optionally create a backup first.
- Stream the remote dump directly into your local database with live progress spinner.
- Display a completion summary with table count.
During fzf selection menus:
| Key | Action |
|---|---|
↑ / ↓ |
Navigate options |
/ |
Fuzzy search |
Enter |
Select |
Esc |
Quit |
At any prompt:
| Input | Action |
|---|---|
q / Q |
Quit (at credential prompts) |
Ctrl+C |
Interrupt with cleanup |
Your credentials are saved in .env. You can edit this file manually at any time.
| Variable | Description |
|---|---|
SSH_IP |
Remote server IP address or hostname. |
SSH_USER |
SSH username for the remote server. |
SSH_PORT |
SSH port (default is 22). |
REMOTE_DB_USER |
MySQL username on the remote server. |
REMOTE_DB_PASS |
MySQL password on the remote server. |
LOCAL_DB_USER |
Local MySQL username (usually root). |
LOCAL_DB_PASS |
Local MySQL password (usually empty). |
LOCAL_DB_PORT |
Local MySQL port (usually 3306). |
.
├── sync-db.sh # Main executable script
├── .env # Saved credentials (gitignored)
├── .env.example # Template for .env
├── .profiles/ # Named profiles (e.g., school.env)
├── backups/ # Automatic pre-sync backups
├── README.md # This file
└── QWEN.md # Project documentation
You can store named profiles in .profiles/ (e.g., .profiles/school.env) to quickly switch between different remote configurations. Source a profile before running the script:
set -a; source .profiles/school.env; set +a
./sync-db.shWarning
This tool will overwrite tables in your target local database. Please ensure you have backed up any critical local data before performing a sync.
| Issue | Solution |
|---|---|
fzf is not installed |
Run brew install fzf |
SSH connection failed |
Verify IP, port, username, and SSH key/password |
Failed to fetch remote databases |
Check remote MySQL credentials and user permissions |
Failed to import into local database |
Ensure Dbngin is running, port is correct, and disk space is available |
No Dbngin mysql binaries found |
Verify Dbngin is installed at /Users/Shared/DBngin/mysql |
Created with ❤️ by Antigravity