You copied production to staging so you could test a plugin update. Five minutes later staging looks perfect and production still works, until someone clicks "sync database back" without a plan and every email link points at staging.example.com.
Staging database sync is where WordPress migrations get emotional. Files are easy to rsync. The database is full of serialized URLs, option rows, and plugin settings that break if you search-replace like it is a text file.
What you are actually syncing
A WordPress database holds posts, users, orders, widget configs, and options like siteurl and home. Page builders and WooCommerce store layout data in meta tables, often serialized PHP strings. One wrong replace turns widgets into empty boxes.
Sync direction matters:
- Production → staging: refresh staging with real content for testing (common, safer direction)
- Staging → production: push tested DB changes live (dangerous without a narrow scope)
Most teams should only push code or specific content changes to production, not wholesale overwrite the live database.
Production to staging (the usual workflow)
- Export production database (mysqldump, host backup tool, or migration plugin).
- Import into staging database on the staging URL.
- Run a serialization-safe search-replace: production domain → staging domain (WP-CLI
search-replacewith `--all-tables` or trusted plugins). - Update
wp_optionssiteurl/home if they still show production. - Disable outbound email on staging (SMTP to blackhole, or plugins like "disable emails") so test orders do not email customers.
- Block search engines (staging noindex, HTTP auth, or disallow in robots).
Our staging environments guide covers why you want this box in the first place.
Staging to production (when you must)
Avoid full database overwrite unless you are launching a brand-new site that never had live traffic. If you only changed content on staging:
- Export specific tables or use migration tools that diff content
- Or re-do content changes on production after testing the process on staging
WooCommerce stores: never copy staging DB over production to "fix" something unless you accept losing orders placed since the sync. Orders are money.
URL and HTTPS gotchas
Replace both http and https variants. Replace www and non-www if both existed in content. CDN URLs (Cloudflare, asset domains) sometimes embed in post content; decide if staging should keep production CDN paths or local assets.
After replace, click: homepage, a post with embeds, menus, WooCommerce shop and cart, and password reset email preview if you send mail from staging by mistake.
Tools that help
WP-CLI on SSH: wp search-replace 'https://live.example.ca' 'https://staging.example.ca' --all-tables with dry-run first.
WP Migrate, Duplicator, All-in-One WP Migration: popular for pushes; read whether they handle serialized data and large tables.
Host staging clones: some panels clone with automatic URL rewrite; verify, do not trust blindly.
What not to do
- Raw SQL update on
wp_postswithout serialization awareness - Sync production DB to staging without disabling staging emails
- Leave staging indexed in Google alongside production
- Store production API keys on staging after sync (payment gateways in test mode only)
Canadian hosting note
Staging on the same Canadian VPS as production keeps latency low for syncs. Staging in the US while production is in Edmonton is fine for testing, but mind data residency if staging holds real customer PII from production copies.
Bottom line
Sync production to staging with serialization-safe URL replaces, no customer emails, and no indexing. Push staging to production rarely and surgically. Files and database are not the same operation, and the database is the one that punishes shortcuts.
Need staging plus safe migration on Canadian infrastructure? Talk with Swift Host. We set up clones and cutovers with rollback in mind.