Skip to main content

Developer Tools (tools/)

The root-level tools/ directory contains developer-facing CLI utilities for database synchronization, S3 media sync, and NFusion product catalog imports. These scripts are run locally (in WSL on Windows) and are never web-accessible.

WSL Required

All bash scripts in tools/ must be run from WSL (Windows Subsystem for Linux) in the project root directory โ€” not from PowerShell or CMD.

cd /mnt/z/Herd/scottsdalemint

Directory Structureโ€‹

tools/
โ”œโ”€โ”€ db-sync/
โ”‚ โ”œโ”€โ”€ db-sync.sh # Main database synchronization script
โ”‚ โ”œโ”€โ”€ setup-db-sync.sh # One-time setup helper
โ”‚ โ”œโ”€โ”€ close-tunnels.ps1 # (Legacy) PowerShell tunnel closer โ€” no longer needed
โ”‚ โ”œโ”€โ”€ db-sync.conf.example # Example configuration file
โ”‚ โ”œโ”€โ”€ db-sync.conf # Your local config (git-ignored)
โ”‚ โ””โ”€โ”€ .env # DB credentials (git-ignored)
โ”œโ”€โ”€ nfusion-import/
โ”‚ โ”œโ”€โ”€ retail-import.php # Convert WooCommerce export โ†’ NFusion retail catalog CSV
โ”‚ โ”œโ”€โ”€ retail-tiers-import.php # Convert WooCommerce export โ†’ NFusion retail price tiers CSV
โ”‚ โ”œโ”€โ”€ dealers-import.php # Convert WooCommerce export โ†’ NFusion dealers catalog CSV
โ”‚ โ””โ”€โ”€ dealers-tiers-import.php# Convert WooCommerce export โ†’ NFusion dealers price tiers CSV
โ”œโ”€โ”€ s3-sync/
โ”‚ โ”œโ”€โ”€ s3-sync.sh # S3 uploads synchronization script
โ”‚ โ”œโ”€โ”€ s3-sync.conf.example # Example configuration file
โ”‚ โ”œโ”€โ”€ s3-sync.conf # Your local config (git-ignored)
โ”‚ โ””โ”€โ”€ .env # AWS credentials (git-ignored)
โ”œโ”€โ”€ hosts-count.php # Analyzes hosts.csv to find top 500 hosts by frequency
โ”œโ”€โ”€ hosts.csv # Input CSV for hosts analysis
โ””โ”€โ”€ hosts.txt / hosts-results.txt # Input/output for host analysis

Database Sync (tools/db-sync/)โ€‹

Version: 1.1.0
Script: tools/db-sync/db-sync.sh

Synchronizes the WordPress MySQL database between environments (production, staging, development, local). Supports remote-to-remote sync, data scrubbing, URL replacement, and selective operation skipping.

Quick Startโ€‹

PowerShell / CMD will not work

db-sync.sh is a bash script and must be run inside WSL. Opening it in PowerShell or Windows CMD will fail. Launch a WSL terminal first:

wsl
cd /mnt/z/Herd/scottsdalemint # adjust drive letter to match your setup
# From the project root in WSL:

# 1. Copy and configure the operational settings file
cp tools/db-sync/db-sync.conf.example tools/db-sync/db-sync.conf
# Edit db-sync.conf as needed (notification email, scrub defaults, etc.)

# 2. Create the credentials .env file (see Configuration section below)
touch tools/db-sync/.env
# Populate it with DB passwords, SSH config, and Aurora endpoints

# 3. Sync production โ†’ local (most common use case)
./tools/db-sync/db-sync.sh --source=production --target=local

# 4. Dry-run first to preview operations
./tools/db-sync/db-sync.sh --source=production --target=local --dry-run

Configurationโ€‹

The db-sync tool uses two separate files that must both exist before running:

FilePurposeTracked in git?
tools/db-sync/db-sync.confOperational settings (copy from .conf.example)No โ€” git-ignored
tools/db-sync/.envSecrets: passwords, SSH keys, Aurora endpointsNo โ€” git-ignored

Creating tools/db-sync/.envโ€‹

Create this file manually โ€” there is no .env.example provided since it contains secrets. Populate it with the following variables (get values from a team member or the Ymir/AWS console):

################################################################################
# Database Sync Configuration
# KEEP THIS FILE SECURE AND DO NOT COMMIT TO VERSION CONTROL
################################################################################

# Database Passwords
DB_PASS_LIVE=<production_aurora_password>
DB_PASS_STAGING_DEVELOPMENT=<staging_and_dev_aurora_password>

# SSH Bastion Host Configuration
# These bastion hosts provide access to the Aurora databases
SSH_BASTION_STG_DEV="bastion-stg-dev.scottsdalemint.com"
SSH_BASTION_PROD="bastion-prod.scottsdalemint.com"
SSH_USER="ubuntu"
SSH_KEY_PATH="/home/<your_wsl_username>/.ssh/scottsdale_bastion_key"

# Aurora Database Endpoints
# Actual database server addresses accessed through the bastion hosts
DB_HOST_STG_DEV="scottsdalemint-aurora-dev.cluster-xxxxx.us-east-1.rds.amazonaws.com"
DB_HOST_PROD="scottsdalemint-aurora-prod.cluster-xxxxx.us-east-1.rds.amazonaws.com"

# Local Database Configuration
# Run 'ipconfig' in cmd.exe to find your local machine IP address
LOCAL_DB_NAME="wp_scottsdale"
LOCAL_DB_HOST="<your_local_machine_ip>"
Finding your local IP

Run ipconfig in Windows CMD and use the IPv4 address of your active network adapter (e.g., 10.10.15.x). This is needed so WSL can reach your local MySQL instance.

Getting the SSH key

The scottsdale_bastion_key private key is required to tunnel through the bastion hosts to Aurora. Obtain this from a senior developer or the shared secrets vault and place it at the path specified in SSH_KEY_PATH. Ensure permissions are set correctly:

chmod 600 ~/.ssh/scottsdale_bastion_key

Supported Environmentsโ€‹

ValueDescription
productionLive site (read-only โ€” export only, never a target)
stagingStaging environment on AWS
developmentDev environment on AWS
localLocal Herd instance (import only, never a source)

Key Featuresโ€‹

FeatureDescription
Multi-environment syncExport from prod/staging/dev, import to staging/dev/local
Remote-to-remote syncDirectly sync staging โ†” development without pulling locally
Data scrubbingOptionally delete orders (60+ days old) and user data on local targets
URL replacementAutomatic search-replace for environment URLs
Dry-run modePreview all operations without making changes
Lockfile protectionPrevents accidental parallel execution
Email notificationsSMTP alerts on completion or failure
Auto WP-CLI installInstalls WP-CLI globally if not found

Common Flagsโ€‹

--source=<env>        Source environment (production, staging, development)
--target=<env> Target environment (staging, development, local)
--dry-run Preview operations without executing them
--skip-migration Skip running WP database migration after import
--skip-search-replace Skip URL search-replace step
--skip-scrub-orders Keep all orders (skip order deletion scrub)
--skip-scrub-users Keep all users (skip user deletion scrub)

How It Worksโ€‹

  1. Opens an SSH tunnel via Ymir CLI to the Aurora database.
  2. Exports the source database with mysqldump.
  3. Runs data-scrubbing SQL to remove orders/users (local targets only, optional).
  4. Imports the dump into the target database.
  5. Runs wp search-replace to swap domain URLs.
  6. For remote targets, uses ymir wp <environment> instead of local WP-CLI.

Requirementsโ€‹

  • Bash 4.0+ or WSL
  • MySQL client and mysqldump
  • PHP 7.4+
  • curl
  • Ymir CLI (vendor/bin/ymir)
  • WP-CLI (auto-installed if absent)
  • sendemail (optional, for notifications)

S3 Media Sync (tools/s3-sync/)โ€‹

Version: 1.0.0
Script: tools/s3-sync/s3-sync.sh

Syncs the WordPress uploads/ folder between S3 buckets (production, staging, development) and the local filesystem. Uses parallel processing for faster transfers.

Quick Startโ€‹

# Copy and configure credentials
cp tools/s3-sync/s3-sync.conf.example tools/s3-sync/s3-sync.conf
# Add AWS credentials to tools/s3-sync/.env

# Sync production S3 โ†’ local uploads folder
./tools/s3-sync/s3-sync.sh --source=production --target=local

# Dry-run first
./tools/s3-sync/s3-sync.sh --source=production --target=local --dry-run

Key Featuresโ€‹

FeatureDescription
Year-folder filteringOnly syncs 2013โ€“2099 year folders, ignoring cache/temp directories
One-way syncFiles are never deleted from the target (safe append-only)
Parallel processingUp to 10 year folders synced simultaneously
Dry-run modeTest without making any changes
Lockfile protectionPrevents parallel execution
Per-year logsIndividual log files for each year folder synced

Requirementsโ€‹

  • Bash 4.0+ or WSL
  • AWS CLI with valid credentials
  • S3 bucket access to Ymir asset buckets

NFusion Import Tools (tools/nfusion-import/)โ€‹

PHP scripts for converting WooCommerce product exports into the CSV format required by the NFusion Solutions product catalog and price-tier import system. Run these when re-syncing the product catalog with NFusion after bulk product changes.

Scriptsโ€‹

retail-import.phpโ€‹

Converts a WooCommerce retail product export CSV (retailscottsdale-productos.csv) into nfusion-retail-import.csv for NFusion catalog import.

Field Mappings:

WooCommerce FieldNFusion FieldNotes
SKUSkuRequired
NameNameRequired
Meta: _metal_weightOunces4 decimal places
Meta: _markup_rate ร— Meta: _metal_weightAskDollarMarkup per oz ร— total oz
Meta: _metal_typeMetalTitle-cased (e.g., Silver)
Metal typeProductFamilye.g., "Silver Bullion"

ProductFamily mapping:

_metal_typeProductFamily
silverSilver Bullion
goldGold Bullion
copperCopper Bullion
platinumPlatinum Bullion
palladiumPalladium Bullion
# Place retailscottsdale-productos.csv in nfusion-import/, then:
php tools/nfusion-import/retail-import.php
# Outputs: tools/nfusion-import/nfusion-retail-import.csv

retail-tiers-import.phpโ€‹

Converts volume pricing tiers from the WooCommerce retail export into nfusion-price-tiers-import.csv for NFusion price-tier import.

php tools/nfusion-import/retail-tiers-import.php

dealers-import.phpโ€‹

Same as retail-import.php but reads from dealersscottsdale-productos.csv and outputs nfusion-dealers-import.csv for the dealers channel catalog.

php tools/nfusion-import/dealers-import.php

dealers-tiers-import.phpโ€‹

Converts dealers volume pricing tiers into nfusion-dealers-tiers-import.csv.

php tools/nfusion-import/dealers-tiers-import.php

Typical Workflowโ€‹

  1. Export dealer and retail product data from WooCommerce (WP Admin โ†’ Products โ†’ Export).
  2. Save CSV files to tools/nfusion-import/ with the expected filenames.
  3. Run the appropriate PHP scripts.
  4. Upload the generated CSV files to the NFusion catalog import portal.

Hosts Analysis (tools/hosts-count.php)โ€‹

A standalone PHP utility for analyzing a hosts.csv file and identifying the top 500 hosts by frequency. Used for traffic analysis and CDN/firewall rule creation.

php tools/hosts-count.php
# Reads: tools/hosts.csv
# Writes: tools/hosts-results.txt

This script is a one-off utility and is not part of any automated process.


Security Notesโ€‹

  • tools/db-sync/.env and tools/s3-sync/.env contain database passwords and AWS credentials โ€” they are git-ignored and must never be committed.
  • Database sync with --target=production is intentionally disabled โ€” production is export-only.
  • Remote-to-remote sync shows an extra confirmation warning to prevent accidental data overwrites.