A robust bash utility for performing WordPress database imports and domain/URL replacements, commonly needed for migrating environments (e.g., production to local/staging). It efficiently handles single-site and multi-domain WordPress Multisite setups.
- π Global Command Access - Available anywhere after installation with
wp-db-import - π§ Universal Bash Compatibility - Works seamlessly across Bash 3.2, 4.x, and 5.x versions (View Compatibility Guide)
- π Project-Specific Configuration System - Auto-saves settings in
wpdb-import.conffile - π Automatic WordPress installation detection (single-site or multisite)
- πΊοΈ Smart Multisite Mapping - Remembers site mappings and prompts only for new sites
- β‘ High-Speed Bulk Post Revision Cleanup (via WP-CLI)
- π§Ή Smart MySQL Commands for Manual Revision Cleanup (when automatic cleanup is skipped)
- β Auto-detects multisite using WP-CLI site functions
- β Generates clean commands without problematic OPTIMIZE TABLE statements
- β Works from any directory with WordPress path detection
- π Auto-Update System - Git-based installations update with
wp-db-import update - π οΈ Modular Architecture - Clean separation of utilities and core functions
- π Clickable Site Links - Terminal links to quickly access local sites
- π§Ή Intelligent domain sanitization (removes protocols, trailing slashes)
- π Robust Multi-Domain/Per-Site Mapping for Multisite
- π Enhanced search-replace (2-4 passes based on source domain type)
- ποΈ Cache and transient clearing via WP-CLI
- π§ͺ Dry-run mode for testing replacements
- π¦ MySQL command generation for network domain tables
- π‘οΈ Comprehensive error handling and logging
- π¨ Colored terminal output with clear progress indicators
- πΈ Stage File Proxy Plugin automatic installation and configuration
- π GitIgnore Protection - Automatically prevents stage-file-proxy plugin commits
- π¦ User-Local Installation - Installs to ~/.local/bin
- π Centralized Version Management - Single VERSION file with automated tracking
| Requirement | Description | Version Notes |
|---|---|---|
| Operating System | macOS/Linux environment with Bash shell | All Bash versions supported (3.2+) |
| Bash Compatibility | Cross-version support with automatic fallbacks | Bash 3.2, 4.x, 5.x |
| WP-CLI | WordPress Command Line Interface | Latest stable version |
| WordPress | WordPress installation with wp-config.php | Single-site or multisite |
| Database | MySQL/MariaDB database with import privileges | 5.7+ or 10.2+ |
| PHP | PHP runtime for WP-CLI operations | 7.4+ recommended |
| File System | Read/write access to WordPress directory | Sufficient disk space for import |
Option 1: Git Clone (Auto-updates enabled)
# 1. Clone the repository
git clone https://github.com/manishsongirkar/wp-db-import-and-domain-replacement-tool.git
cd wp-db-import-and-domain-replacement-tool
# 2. Install globally
./install.sh
# 3. Use from anywhere!
cd ~/Local\ Sites/mysite/app/public
wp-db-importOption 2: ZIP Download (Manual updates)
# 1. Download and extract ZIP from GitHub releases
# 2. Navigate to extracted folder
cd wp-db-import-and-domain-replacement-tool
# 3. Install globally
./install.sh
# 4. Use from anywhere!
cd ~/Local\ Sites/mysite/app/public
wp-db-import# Test installation
wp-db-import --help
# Check version and installation info
wp-db-import versionCommand not found:
# Check if ~/.local/bin is in PATH
echo $PATH | grep -q "$HOME/.local/bin" && echo "β
In PATH" || echo "β Not in PATH"
# Add to PATH manually (for current session)
export PATH="$HOME/.local/bin:$PATH"
# Add to shell profile (permanent)
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc # or ~/.bashrc
source ~/.zshrc # or ~/.bashrcPermission issues:
# Check symlink and permissions
ls -la ~/.local/bin/wp-db-import
ls -la "$(readlink ~/.local/bin/wp-db-import)"
# Recreate symlink if needed
rm ~/.local/bin/wp-db-import
./install.shAuto-updates (Git installations):
wp-db-import update # Automatic git pullManual updates (ZIP installations):
# Download latest version and replace files
# Then re-run: ./install.sh# Main database import wizard
wp-db-import
# Configuration management
wp-db-import config-show # Show unified configuration status
wp-db-import config-create # Create configuration with site mappings
wp-db-import config-validate # Validate configuration structure
wp-db-import config-edit # Open configuration in editor
# Show local site links
wp-db-import show-links
# Auto-setup stage file proxy (detects config)
wp-db-import setup-proxy
# Generate database revision cleanup commands
wp-db-import show-cleanup
# Update to latest version (git only)
wp-db-import update
# Show version info
wp-db-import version
# Get help
wp-db-import --helpThe tool now features a project-specific configuration system that remembers your settings and site mappings, making subsequent imports much faster and more convenient.
The configuration file wpdb-import.conf is automatically created in your WordPress root directory (same location as wp-config.php), making it project-specific.
# ===============================================
# WordPress Database Import Configuration
# ===============================================
[general]
sql_file=production-database.sql
old_domain=admin.example.com
new_domain=example.test
all_tables=true
dry_run=false
clear_revisions=true
setup_stage_proxy=true
auto_proceed=false
[site_mappings]
# Format: blog_id:old_domain:new_domain
1:admin.example.com:example.test
2:blog.example.com:example.test/blog
3:shop.example.com:example.test/shop
4:news.example.com:example.test/news
5:support.example.com:example.test/support
6:docs.example.com:example.test/docs- First Run: The tool prompts for all settings and creates the config file
- Subsequent Runs: Settings are loaded automatically from the config file
- Missing Mappings: If new sites are detected, you're only prompted for those
- Auto-Update: The config file is updated with any new mappings you provide
# Show unified configuration status
wp-db-import config-show
# Create configuration with site mappings interactively
wp-db-import config-create
# Validate configuration structure and format
wp-db-import config-validate
# Open configuration in your default editor
wp-db-import config-editYou can manually edit the wpdb-import.conf file in your WordPress root directory:
# Edit with nano
nano wpdb-import.conf
# Edit with VSCode
code wpdb-import.conf- β‘ Faster Imports: No need to re-enter the same information
- πΊοΈ Site Mapping Memory: Multisite mappings are remembered
- π Incremental Setup: Only prompts for new/missing sites
- π Project-Specific: Each WordPress project has its own config
- π§ͺ Testing-Friendly: Easily switch between dry-run and live mode
Ready-to-use configuration examples are available in the project root:
wpdb-import-example-single.conf- For standard WordPress siteswpdb-import-example-multisite.conf- For WordPress Multisite networksUSAGE.md- Complete usage guide with setup instructions and examples
Quick setup:
# Copy example to your WordPress root
cp wpdb-import-example-single.conf ~/path/to/wordpress/wpdb-import.conf
# Edit the configuration
nano ~/path/to/wordpress/wpdb-import.conf- Navigate to your WordPress root directory (where
wp-config.phpfile present) - Place your SQL (
.sql) file in the same directory - Run the global command:
wp-db-import
- Follow the interactive prompts
# Create timestamped backup with compression
wp db export "backup-$(date +%Y%m%d-%H%M%S).sql.gz" --compress
# Verify backup integrity
gunzip -t "backup-$(date +%Y%m%d-%H%M%S).sql.gz"
# Store backup in secure location
cp backup-*.sql.gz ~/wp-backups/$(basename $(pwd))/All options can be pre-configured in your wpdb-import.conf file, eliminating the need for manual input on subsequent runs:
| Configuration Key | Description | Default Value | Config Example |
|---|---|---|---|
| sql_file | Database dump file to import | vip-db.sql |
sql_file=production-database.sql |
| old_domain | Production domain to search for | Required input | old_domain=example.com |
| new_domain | Local/staging domain to replace with | Required input | new_domain=example.test |
| all_tables | Include non-WordPress prefixed tables | true |
all_tables=true |
| dry_run | Preview changes without applying them | false |
dry_run=false |
| clear_revisions | Delete all post revisions before search-replace | true |
clear_revisions=true |
| setup_stage_proxy | Automatically configure stage file proxy | true |
setup_stage_proxy=true |
| auto_proceed | Skip confirmation prompts | false |
auto_proceed=false |
| Option | Description | Default | Advanced Notes |
|---|---|---|---|
| SQL filename | Database dump file to import | From config or vip-db.sql |
Supports absolute and relative paths; auto-detected from config |
| Old Domain | Production domain to search for | From config or prompt | Auto-sanitized (protocols/slashes removed); config override available |
| New Domain | Local/staging domain to replace with | From config or prompt | Security validation applied; config override available |
| Revision cleanup | Delete all post revisions before search-replace | From config or Optional (Y/n) | High-speed bulk operation using xargs; MySQL commands shown when skipped |
| All tables | Include non-WordPress prefixed tables | From config or Recommended (Y/n) | Essential for full migrations; remembers choice in config |
| Dry-run mode | Preview changes without applying them | From config or Optional (y/N) | Shows exact operations to be executed; easily toggled in config |
| Enhanced www/non-www handling | Automatic detection and conditional processing of www variants | Automatic | Smart 2-4 pass system based on source domain |
| Multisite mapping | Per-subsite domain mapping (auto-detected) | Smart prompts with config memory | Remembers mappings, only prompts for new sites |
| Automatic DB Updates | wp_blogs and wp_site table updates via wp eval | Automatic for multisite | Executed before search-replace operations |
| Stage File Proxy Setup | Interactive setup prompt for media management | From config or Default Yes (Y/n) | Includes automatic plugin installation |
| Cache clearing | Flush object cache, rewrites, and transients | Automatic | Network-wide for multisite |
-
οΏ½ Configuration Discovery & Setup
- Config file detection: Searches for
wpdb-import.confin WordPress root directory - First-time setup: Interactive prompts with automatic config file creation
- Subsequent runs: Auto-loads settings from config file with override options
- Smart defaults: Pre-fills values from config while allowing runtime overrides
- Config file detection: Searches for
-
οΏ½π Environment Detection
- WordPress root directory discovery (works from any subdirectory)
- Installation type detection via multiple methods (database analysis, wp-config.php, WP-CLI)
- Multisite configuration analysis (subdomain vs subdirectory)
-
π¦ Database Import Setup
- SQL file selection (config-aware with fallback to
vip-db.sql) - Domain mapping configuration (production β local) with config memory
- Import confirmation with summary display
- Progress tracking with elapsed time
- SQL file selection (config-aware with fallback to
-
ποΈ Pre-Processing Operations
- High-speed bulk revision cleanup using xargs (config-controlled, site-by-site for multisite)
- MySQL commands for manual revision cleanup (shown when automatic cleanup is skipped)
- Table scope selection (
--all-tablesoption, remembers config preference) - Dry-run mode selection for safe testing (config-configurable)
-
π Enhanced Domain Replacement Process
- www/non-www Detection: Automatic detection of source domain type using regex pattern
^www\. - Smart Pass System: Conditional execution based on source domain:
- Non-www source: 2 passes (standard + serialized URL replacement)
- www source: 4 passes (non-www standard + www standard + non-www serialized + www serialized)
- Single-site: Enhanced search-replace with conditional www handling
- Multisite (subdirectory): Network-wide replacement with shared domain
- Multisite (subdomain): Configuration-aware site mapping with smart prompts
- Clean Output: Dynamic pass numbering with descriptive messages (no confusing skip notifications)
- www/non-www Detection: Automatic detection of source domain type using regex pattern
-
πΊοΈ Intelligent Multisite Mapping (Configuration-Enhanced)
- Config-aware mapping: Loads existing site mappings from configuration
- Incremental prompts: Only asks for mappings for new/unmapped sites
- Smart defaults: Suggests intelligent subdirectory mappings based on existing config
- Auto-update config: Saves new mappings back to configuration file
- Mapping validation: Ensures consistency and prevents conflicts
-
π Database Structure Updates (Multisite)
- Automatic Updates: wp_blogs and wp_site tables updated via wp eval before search-replace
- Fallback Commands: Manual MySQL commands generated only if automatic updates fail
- Verification: Success/failure reporting for each operation
-
π§Ή Post-Processing Cleanup
- Object cache flushing
- Rewrite rules regeneration
- Transient data cleanup
-
πΈ Stage File Proxy Integration (Configuration-Aware)
- Config-driven setup: Uses configuration setting to determine if setup is needed
- Smart activation: Detects existing plugin and skips redundant setup
- Automatic plugin installation from GitHub release if not present (multiple fallback methods)
- Context-aware activation: Network-wide for multisite, site-wide for single-site
- Mapping-aware configuration: Uses established domain mappings from import process
- HTTPS protocol enforcement: Security compliance with proper protocol handling
- π GitIgnore Protection: Automatically adds plugin to .gitignore to prevent accidental commits
-
πΎ Configuration Updates & Memory
- Auto-save new mappings: Any new site mappings are saved to config file
- Setting persistence: User choices are remembered for future runs
- Config validation: Ensures configuration integrity after updates
Terminal Input/Output:
$ wp-db-import
π§ WordPress Database Import & Domain Replace Tool
====================================================
β
WordPress root found: /Users/john/Sites/example-site/app/public
π No configuration file found.
π‘ Creating new config: /Users/john/Sites/example-site/app/public/wpdb-import.conf
π¦ Enter SQL file name (default: vip-db.sql): production-database.sql
β
Found SQL file: production-database.sql
π File size: 45.2 MB
π Enter the OLD (production) domain to search for: https://www.example.com/
π Enter the NEW (local) domain/base URL to replace with: https://example.test/
π Creating configuration file...
β
Configuration file created: wpdb-import.conf
π§Ή Cleaned search domain: 'https://www.example.com/' β 'www.example.com'
π§Ή Cleaned replace domain: 'https://example.test/' β 'example.test'
π§Ύ Summary:
π¦ SQL file: production-database.sql
π Search for: www.example.com
π Replace with: example.test
Proceed with database import? (Y/n): y
β³ Importing database...
β
Database import successful! [Completed in 00:14]
π Validating domain configuration...
β
Detected domain in database: www.example.com
π Checking WordPress installation type...
β
Single site installation detected
Clear ALL post revisions: enabled (from config)
Press Enter to confirm, or 'n' to skip revision cleanup:
β
Proceeding with revision cleanup
ποΈ Clearing ALL Post Revisions...
β
Revisions deleted successfully
Include --all-tables: enabled (from config)
β
Will include all tables.
Run in dry-run mode: live mode (from config)
οΏ½ Running search-replace operations...
π SEARCH-REPLACE OPERATIONS
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Single Site Processing:
From: www.example.com
To: example.test
Step 1: β
Standard URL replacement complete
Step 2: β
Serialized data replacement complete
π§Ή Flushing WordPress and WP-CLI caches & transients...
β
Object cache flushed.
β
Rewrite rules flushed.
β
All transients deleted.
πΈ Stage File Proxy Setup
Setup stage file proxy: enabled (from config)
β
Plugin activated successfully
π Securing plugin from accidental repository commits...
β
Plugin successfully added to .gitignore
β
Configured: example.test β https://www.example.com
================================================================
π LOCAL SITE ACCESS LINKS
================================================================
β
Your WordPress Single Site is ready:
π Frontend: http://example.test
βοΈ Admin: http://example.test/wp-admin
================================================================
β±οΈ Execution Time: 00:18 (mm:ss)Terminal Input/Output:
$ wp-db-import
π§ WordPress Database Import & Domain Replace Tool
====================================================
β
WordPress root found: /Users/john/Sites/example-site/app/public
β
Configuration found: /Users/john/Sites/example-site/app/public/wpdb-import.conf
π Using configuration settings...
π¦ SQL file: production-database.sql (from config)
β
Found SQL file: production-database.sql
π File size: 45.2 MB
π OLD (production) domain: www.example.com (from config)
Press Enter to use this domain, or type a new domain to override:
π NEW (local) domain: example.test (from config)
Press Enter to use this domain, or type a new domain to override:
π§Ύ Summary:
π¦ SQL file: production-database.sql
π Search for: www.example.com
π Replace with: example.test
β
Auto-proceeding with database import (from config)
β³ Importing database...
β
Database import successful! [Completed in 00:12]
π Validating domain configuration...
β
Detected domain in database: www.example.com
π Checking WordPress installation type...
β
Single site installation detected
Clear ALL post revisions: enabled (from config)
β
Proceeding with revision cleanup
ποΈ Clearing ALL Post Revisions...
β
Revisions deleted successfully
Include --all-tables: enabled (from config)
Run in dry-run mode: live mode (from config)
π Running search-replace operations...
β
Single site search-replace completed successfully!
π§Ή Flushing WordPress and WP-CLI caches & transients...
β
Object cache flushed.
β
Rewrite rules flushed.
β
All transients deleted.
πΈ Stage File Proxy Setup
Setup stage file proxy: enabled (from config)
β
Plugin already activated
π Securing plugin from accidental repository commits...
β
The Stage File Proxy plugin will now be ignored by Git.
β
Configured: example.test β https://www.example.com
================================================================
π LOCAL SITE ACCESS LINKS
================================================================
β
Your WordPress Single Site is ready:
π Frontend: http://example.test
βοΈ Admin: http://example.test/wp-admin
================================================================
β±οΈ Execution Time: 00:15 (mm:ss)Terminal Input/Output:
$ wp-db-import
π§ WordPress Database Import & Domain Replace Tool
====================================================
β
WordPress root found: /Users/john/Sites/example-multisite/app/public
π No configuration file found.
π‘ Creating new config: /Users/john/Sites/example-multisite/app/public/wpdb-import.conf
π¦ Enter SQL file name (default: vip-db.sql): multisite-production.sql
β
Found SQL file: multisite-production.sql
π File size: 128.5 MB
π Enter the OLD (production) domain to search for: https://admin.example.com/
π Enter the NEW (local) domain/base URL to replace with: https://example.test/
π Creating configuration file...
β
Configuration file created: wpdb-import.conf
π§Ή Cleaned search domain: 'https://admin.example.com/' β 'admin.example.com'
π§Ή Cleaned replace domain: 'https://example.test/' β 'example.test'
π§Ύ Summary:
οΏ½ SQL file: multisite-production.sql
οΏ½π Search for: admin.example.com
π Replace with: example.test
Proceed with database import? (Y/n): y
β³ Importing database...
β
Database import successful! [Completed in 00:28]
π Validating domain configuration...
β
Detected domain in database: admin.example.com
π Checking WordPress installation type...
β
Multisite detected via database analysis
Clear ALL post revisions: enabled (from config)
β
Proceeding with revision cleanup
ποΈ Clearing ALL Post Revisions...
β
All revisions deleted across 6 sites
Include --all-tables: enabled (from config)
Run in dry-run mode: live mode (from config)
π Subdomain Multisite Detected
Using configuration-aware site mapping...
πΊοΈ Site Mapping Configuration
===============================
β οΈ Missing mappings for 6 sites:
ββ Processing Site 1 ββββββββββββββββββββββββββββββββββββββ
β Domain: admin.example.com
β Path: /
β Enter local URL for Main Site (default: example.test): example.test
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
Mapping confirmed:
admin.example.com β example.test
(Blog ID: 1, Path: /)
ββ Processing Site 2 ββββββββββββββββββββββββββββββββββββββ
β Domain: shop.example.com
β Path: /
β Enter local URL for Blog ID 2 (default: example.test/shop):
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
Mapping confirmed:
shop.example.com β example.test/shop
(Blog ID: 2, Path: /)
ββ Processing Site 3 ββββββββββββββββββββββββββββββββββββββ
β Domain: blog.example.com
β Path: /
β Enter local URL for Blog ID 3 (default: example.test/blog):
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
Mapping confirmed:
blog.example.com β example.test/blog
(Blog ID: 3, Path: /)
ββ Processing Site 4 ββββββββββββββββββββββββββββββββββββββ
β Domain: news.example.com
β Path: /
β Enter local URL for Blog ID 4 (default: example.test/news):
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
Mapping confirmed:
news.example.com β example.test/news
(Blog ID: 4, Path: /)
ββ Processing Site 6 ββββββββββββββββββββββββββββββββββββββ
β Domain: support.example.com
β Path: /
β Enter local URL for Blog ID 6 (default: example.test/support):
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
Mapping confirmed:
support.example.com β example.test/support
(Blog ID: 6, Path: /)
ββ Processing Site 7 ββββββββββββββββββββββββββββββββββββββ
β Domain: docs.example.com
β Path: /
β Enter local URL for Blog ID 7 (default: example.test/docs):
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
Mapping confirmed:
docs.example.com β example.test/docs
(Blog ID: 7, Path: /)
β
Configuration updated with new site mappings
π§Ύ Domain mapping summary:
βΉοΈ Main site detected: Blog ID 1 (via WordPress database)
π [ID: 1] admin.example.com/ β example.test
π [ID: 2] shop.example.com/ β example.test/shop
π [ID: 3] blog.example.com/ β example.test/blog
π [ID: 4] news.example.com/ β example.test/news
π [ID: 6] support.example.com/ β example.test/support
π [ID: 7] docs.example.com/ β example.test/docs
Proceed with search-replace for all sites? (Y/n): y
π§ Updating wp_blogs and wp_site tables (before search-replace)...
β
Database tables wp_blogs & wp_site updated successfully!
π Starting search-replace operations...
π Site 1 (Main): admin.example.com β example.test
Step 1: β
Standard URL replacement complete
Step 2: β
Serialized data replacement complete
π Site 2: shop.example.com β example.test/shop
Step 1: β
Standard URL replacement complete
Step 2: β
Serialized data replacement complete
π Site 3: blog.example.com β example.test/blog
Step 1: β
Standard URL replacement complete
Step 2: β
Serialized data replacement complete
π Site 4: news.example.com β example.test/news
Step 1: β
Standard URL replacement complete
Step 2: β
Serialized data replacement complete
π Site 6: support.example.com β example.test/support
Step 1: β
Standard URL replacement complete
Step 2: β
Serialized data replacement complete
π Site 7: docs.example.com β example.test/docs
Step 1: β
Standard URL replacement complete
Step 2: β
Serialized data replacement complete
π§Ή Flushing WordPress and WP-CLI caches & transients...
β
Object cache flushed.
β
Rewrite rules flushed.
β
All transients deleted.
πΈ Stage File Proxy Setup
Setup stage file proxy: enabled (from config)
β
Plugin activated network-wide successfully
β
Configuring 6 sites with stage-file-proxy
β
Site 1 (example.test): Configured β https://admin.example.com
β
Site 2 (example.test/shop): Configured β https://shop.example.com
β
Site 3 (example.test/blog): Configured β https://blog.example.com
β
Site 4 (example.test/news): Configured β https://news.example.com
β
Site 6 (example.test/support): Configured β https://support.example.com
β
Site 7 (example.test/docs): Configured β https://docs.example.com
================================================================
π LOCAL SITE ACCESS LINKS
================================================================
β
Your WordPress Multisite is ready:
π Main Site (ID: 1): http://example.test
π Subsite (ID: 2): http://example.test/shop
π Subsite (ID: 3): http://example.test/blog
π Subsite (ID: 4): http://example.test/news
π Subsite (ID: 6): http://example.test/support
π Subsite (ID: 7): http://example.test/docs
π‘ Network Admin: Add /wp-admin/network/ to any of the above URLs
================================================================
β±οΈ Execution Time: 00:45 (mm:ss)Terminal Input/Output:
$ wp-db-import
π§ WordPress Database Import & Domain Replace Tool
====================================================
β
WordPress root found: /Users/john/Sites/example-multisite/app/public
β
Configuration found: /Users/john/Sites/example-multisite/app/public/wpdb-import.conf
π Using configuration settings...
π¦ SQL file: multisite-production.sql (from config)
β
Found SQL file: multisite-production.sql
π File size: 128.5 MB
π OLD (production) domain: admin.example.com (from config)
Press Enter to use this domain, or type a new domain to override:
π NEW (local) domain: example.test (from config)
Press Enter to use this domain, or type a new domain to override:
π§Ύ Summary:
π¦ SQL file: multisite-production.sql
π Search for: admin.example.com
π Replace with: example.test
β
Auto-proceeding with database import (from config)
β³ Importing database...
β
Database import successful! [Completed in 00:25]
π Validating domain configuration...
β
Detected domain in database: admin.example.com
π Checking WordPress installation type...
β
Multisite detected via database analysis
Clear ALL post revisions: enabled (from config)
ποΈ Clearing ALL Post Revisions...
β
All revisions deleted across 6 sites
οΏ½ Subdomain Multisite Detected
Using configuration-aware site mapping...
πΊοΈ Site Mapping Configuration
===============================
β
Found existing mappings for 6/6 sites:
Blog ID Production Domain β Local Domain
------- ----------------- ------------
1 admin.example.com β example.test
2 shop.example.com β example.test/shop
3 blog.example.com β example.test/blog
4 news.example.com β example.test/news
6 support.example.com β example.test/support
7 docs.example.com β example.test/docs
π All sites are already mapped! Proceeding with existing configuration.
β
Auto-proceeding with search-replace for all sites (from config)
π§ Updating wp_blogs and wp_site tables (before search-replace)...
β
Database tables wp_blogs & wp_site updated successfully!
π Starting search-replace operations...
π Site 1 (Main): admin.example.com β example.test
Step 1: β
Standard URL replacement complete
Step 2: β
Serialized data replacement complete
οΏ½ Site 2: shop.example.com β example.test/shop
Step 1: β
Standard URL replacement complete
Step 2: β
Serialized data replacement complete
π Site 3: blog.example.com β example.test/blog
Step 1: β
Standard URL replacement complete
Step 2: β
Serialized data replacement complete
π Site 4: news.example.com β example.test/news
Step 1: β
Standard URL replacement complete
Step 2: β
Serialized data replacement complete
π Site 6: support.example.com β example.test/support
Step 1: β
Standard URL replacement complete
Step 2: β
Serialized data replacement complete
π Site 7: docs.example.com β example.test/docs
Step 1: β
Standard URL replacement complete
Step 2: β
Serialized data replacement complete
π§Ή Flushing WordPress and WP-CLI caches & transients...
β
Object cache flushed.
β
Rewrite rules flushed.
β
All transients deleted.
πΈ Stage File Proxy Setup
Setup stage file proxy: enabled (from config)
β
Plugin already activated network-wide
π Securing plugin from accidental repository commits...
β
The Stage File Proxy plugin will now be ignored by Git.
β
Configuring 6 sites with stage-file-proxy
β
Site 1 (example.test): Already configured
β
Site 2 (example.test/shop): Already configured
β
Site 3 (example.test/blog): Already configured
β
Site 4 (example.test/news): Already configured
β
Site 6 (example.test/support): Already configured
β
Site 7 (example.test/docs): Already configured
================================================================
π LOCAL SITE ACCESS LINKS
================================================================
β
Your WordPress Multisite is ready:
π Main Site (ID: 1): http://example.test
π Subsite (ID: 2): http://example.test/shop
π Subsite (ID: 3): http://example.test/blog
π Subsite (ID: 4): http://example.test/news
π Subsite (ID: 6): http://example.test/support
π Subsite (ID: 7): http://example.test/docs
π‘ Network Admin: Add /wp-admin/network/ to any of the above URLs
================================================================
β±οΈ Execution Time: 00:32 (mm:ss)- Single-site installations
- Multisite subdomain networks
- Multisite subdirectory networks (including multi-domain to single-domain migrations)
The tool includes a sophisticated revision cleanup system that automatically generates MySQL commands when automatic cleanup is skipped or unavailable.
β Smart Auto-Detection:
- Automatically detects single site vs multisite installations
- Uses WP-CLI
wp site listfor robust multisite detection - Works even when direct database queries fail
β Clean Command Generation:
- Generates safe DELETE commands
- Individual commands for each subsite in multisite networks
- Clean output format with blog ID labeling
β Flexible Usage:
- Can be run from any directory with WordPress path parameter
- Integrates seamlessly with main import script
- Available as standalone command:
wp-db-import show-cleanup - Conditional display when automatic cleanup is skipped
Manual commands are only shown if automatic updates fail:
-- Update the main network domain
UPDATE wp_site SET domain = 'example.test' WHERE id = 1;
-- Update individual blog domains (each subsite gets unique domain)
UPDATE wp_blogs SET domain = "blog.example.test", path = "/" WHERE blog_id = 2;
UPDATE wp_blogs SET domain = "shop.example.test", path = "/" WHERE blog_id = 3;
UPDATE wp_blogs SET domain = "news.example.test", path = "/" WHERE blog_id = 4;
UPDATE wp_blogs SET domain = "support.example.test", path = "/" WHERE blog_id = 6;
UPDATE wp_blogs SET domain = "docs.example.test", path = "/" WHERE blog_id = 7;-- Update the main network domain
UPDATE wp_site SET domain = 'example.test' WHERE id = 1;
-- Update blog domains (shared domain with individual paths)
UPDATE wp_blogs SET domain = "example.test", path = "/" WHERE blog_id = 1; -- Main site
UPDATE wp_blogs SET domain = "example.test", path = "/blog/" WHERE blog_id = 2;
UPDATE wp_blogs SET domain = "example.test", path = "/shop/" WHERE blog_id = 3;
UPDATE wp_blogs SET domain = "example.test", path = "/news/" WHERE blog_id = 4;
UPDATE wp_blogs SET domain = "example.test", path = "/support/" WHERE blog_id = 6;
UPDATE wp_blogs SET domain = "example.test", path = "/docs/" WHERE blog_id = 7;The tool provides comprehensive configuration management for project-specific settings:
Display your current unified configuration settings in a user-friendly format:
wp-db-import config-showShows all general settings, site mappings, auto-detection status, and configuration file location.
Interactively create a new configuration file with guided prompts and site mappings:
wp-db-import config-createWalks through all settings including site mappings and creates a properly formatted unified config file.
Check your configuration file for proper structure, format and required settings:
wp-db-import config-validateValidates INI format, required sections, site mappings, and setting completeness.
Open your configuration file in your preferred editor:
wp-db-import config-editUses your $EDITOR environment variable or defaults to nano.
Automatically setup the Stage File Proxy plugin using existing configuration or interactive mapping:
wp-db-import setup-proxyAuto-detects existing configuration and applies site mappings automatically. Falls back to interactive mode only if no config exists. Configures media proxy settings for both single-site and multisite installations. Note: Automatically includes GitIgnore protection to prevent accidental plugin commits.
The tool includes comprehensive GitIgnore management for Stage File Proxy plugin:
Automatic Protection (included in all setup processes):
- Automatically adds
/plugins/stage-file-proxy/towp-content/.gitignore - Prevents accidental commits of local/staging-only plugin to repository
- Works across all Unix-based systems (macOS, Linux, Flywheel)
Manual GitIgnore Operations (available via module functions):
# Load gitignore manager module
source lib/utilities/gitignore_manager.sh
# Add stage-file-proxy to .gitignore
add_stage_file_proxy_to_gitignore
# Check current gitignore status
show_stage_file_proxy_gitignore_status
# Remove from gitignore (if needed)
remove_stage_file_proxy_from_gitignoreDisplay clickable links to local WordPress sites:
wp-db-import show-linksRequirements: Must be run from within a WordPress directory with WP-CLI installed
Generate MySQL commands for manual revision cleanup with enhanced auto-detection:
# Auto-detect WordPress installation and generate commands
wp-db-import show-cleanup
# Use from any directory with WordPress path
wp-db-import show-cleanup /path/to/wordpressProvides safe DELETE commands for manual revision cleanup when automatic cleanup is unavailable.
Check current version and update information:
# Show version and git information
wp-db-import version
# Update to latest version (git installations only)
wp-db-import updateGet comprehensive help and usage information:
wp-db-import --helpShows all available commands, setup instructions, and usage examples.
- Uses absolute paths to prevent directory traversal
- Validates all user inputs
- Sanitizes domain inputs
- Uses temporary files with process-specific names
- Prevents SQL injection in generated commands
wp-db-import- Global command executable with comprehensive subcommand supportimport_wp_db.sh- Main database import and domain replacement script with config integrationinstall.sh- User-local installation script with symlink managementuninstall.sh- Clean removal script with complete cleanupVERSION- Centralized version management file with semantic versioning
wpdb-import-example-single.conf- Single-site configuration template with comprehensive settingswpdb-import-example-multisite.conf- Multisite configuration template with site mapping examplesUSAGE.md- Complete configuration setup guide with practical examples and workflows
lib/
βββ version.sh # Version management utilities and git integration
βββ module_loader.sh # Automatic module discovery and loading system
βββ core/ # Core functionality modules
β βββ utils.sh # Utility functions, domain sanitization, file operations
βββ config/ # Configuration management system
β βββ config_manager.sh # Config file operations, parsing, validation, creation
β βββ integration.sh # Config integration with import flow, smart prompting
βββ database/ # Database operation modules (NEW)
β βββ search_replace.sh # Advanced search-replace with multisite support
βββ utilities/ # Standalone utility modules
βββ site_links.sh # Show local site links with clickable URLs
βββ stage_file_proxy.sh # Media proxy setup with automatic plugin management
βββ revision_cleanup.sh # Revision cleanup commands with multisite detection- π INI-style Configuration: Standard format with
[general]and[site_mappings]sections - π Auto-Discovery: Searches WordPress root directory for project-specific configs
- πΎ Auto-Save: Remembers user choices and site mappings for subsequent runs
- π§ Smart Prompts: Only asks for missing information, shows existing values
- β Validation: Comprehensive config file format and content validation
- π§ Management Commands: Create, show, edit, and validate configuration files
- π Temporary Files: Creates process-specific log files in
/tmp/(PID-based collision prevention) - π§Ή Auto-Cleanup: Automatically removes temporary files on exit
- π Operation Logging: Comprehensive logging of all WP-CLI operations for troubleshooting
- π Symlink Installation: Enables instant updates without reinstallation
- β‘ Configuration Caching: Loads and caches config settings for improved performance
- π οΈ Modular Design: Clean separation of concerns with dedicated modules
- π¦ Auto-Loading: Dynamic module loading based on functionality needs
- π Plugin Architecture: Easy extension with new utility modules
- π Configuration API: Consistent interface for config operations across modules
- π§ͺ Error Handling: Comprehensive error handling and graceful degradation
- π Automatic Integration: All stage-file-proxy setups include automatic .gitignore protection
- π Cross-Platform: Works reliably across macOS, Linux, and Flywheel hosting environments
- π‘οΈ Repository Safety: Prevents accidental commits of local/staging-only plugins
- π Smart Detection: Auto-detects WordPress root directory and wp-content location
- π§ Manual Control: Standalone functions available for advanced gitignore management
- β Validation: Comprehensive permission and file existence checking
- π Status Reporting: Clear feedback about gitignore operations and current status
# Check recent error logs
tail -100 /tmp/wp_*_$$.log | grep -i error
# Monitor WordPress debug logs
tail -f wp-content/debug.log | grep -E "(FATAL|ERROR|WARNING)"# Remove all logs for current process
rm -f /tmp/wp_*_$$.log /tmp/wp_*_$$.csv
# Remove all WordPress tool logs (all processes)
rm -f /tmp/wp_*_*.log /tmp/wp_*_*.csv
# Find and remove old logs (older than 1 day)
find /tmp -name "wp_*_*.log" -mtime +1 -delete
find /tmp -name "wp_*_*.csv" -mtime +1 -delete
# Clean up WP-CLI cache files
find /tmp -type f -name "wp-cli-*" -mtime +1 -delete 2>/dev/nullFor additional documentation, see:
- Bash Compatibility Guide - Cross-version bash support and compatibility features
- Usage Guide - Comprehensive usage examples and workflows
- Installation Methods - Detailed installation options and troubleshooting
- Version Management - Version control and update procedures
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.
Manish Songirkar (@manishsongirkar)