How to sync WordPress / WooCommerce staging and production site. A current overview.

The problem scenario

I have come across many different scenarios and tickets where it would have been mighty helpful to be able to sync two WooCommerce sites. This is one of my favourite subjects so I try to keep tabs on various tools and also set aside time to test promising solutions.

Understanding the sync scenario for WordPress

So what do you need to do to actually sync to WorPress sites? In order to able to sync two WordPress / WooCommerce instances we need to basically sync two things.

  1. the /wp-content/ folder – a file sync job
  2. the complete database – a database sync job

As for number 1) syncing files remotely is relatively simple. Most modern FTP clients can do it fine and have the feature built in.

But: Conflict is always hard.

What is a conflict? When two files / two datasets have the exact same file name, things get difficult. You need to set a deciding factor, for example ‘newer date overwrites older date’.

However there must be one source of truth. What if two developers worked on the same file during the same time period? In that case files need to be merged first and then deployed. Someone has to take a look at both sides and merge the data in a way that still makes sense. This often requires two- and three-way comparison of both files. There are of course tools for this, here are two examples: http://meldmerge.org/ for Linux and a free online tool: http://www.mergely.com/ – I google for “diff merge” to find these.

Merging needs to be done before and in person. And I have yet to see anything that can recognise and handle this complicated process during a file sync procedure.

Where does WooCommerce store it’s data

WooCommerce tries to stay as extendable and compatible as possible. You can glimpse at our coding principles here:
https://docs.woocommerce.com/document/create-a-plugin/

Specifically this is something you should remember: https://docs.woocommerce.com/document/create-a-plugin/#section-6 – custom database tables structures are to be avoided. In short this means the following.

  •  WooCommerce Orders and Products are custom post types and stored in the wp_post table.
  • All relevant order and product data is stored as meta info via custom fields and saved in the wp_postmeta or saved as options via wp_options.

The database sync trouble

The way I understand it, the problem with keeping track of WordPress database changes is the post_ID. As content is added and both sites modified the hierarchy and order of the post_IDs can develop in different ways.

This means that very quickly two sites who seem identical now have different information in posts with the same ID – hope this last bit made sense so far. If not, please let me know in the comments.

So how do you tell what is the source of truth? You cannot really. In that case you would have to write one of the data-sets anew with a different ID. Think of when you copy files on your computer and are asked what to do as identical files names are encountered: When selecting “Copy and keep both files”, your computer appends a ‘-1’ to the file and copies the data over. This would also work well here in a sense that no data is lost.

In the case of database entries however, this breaks the dependencies: for example the link to the user, the corresponding order etc. all this information gets unhinged since the post_ID changes.

Bummer.

When merging you have to account for all these scenarios.
So yeah, merging is uber, mega, final-boss-level difficult.

My tools overview for tackling WooCommerce sync

I have tried many tools, only one does live up to the job thus far.
Lets start with the winner.

Commercial Plugin: WP-Stagecoach
https://wpstagecoach.com/

WP-stagecoach works from my experience and successfully merges a staging and production site. I did test it briefly, but did not test thoroughly with WooCommerce yet. The drawback is that you do not own the staging site. The staging site data is kept on their server.

However they are working on this:
https://wpstagecoach.com/wp-stagecoach-web-hosts/

WordPress Plugin: Database Sync
https://wordpress.org/plugins/database-sync/

I have not tested this yet.
The description reads “can pull or push the entire database between servers with just a click”.

I expect it to ‘just’ do a full database push and pull.

GitHub Plugin: Versionpress
http://versionpress.net/

Versionpress is based on Git.

They have a very good blog article that explains the process of merging and it’s challenges: https://blog.versionpress.net/2015/09/versionpress-2-0-staging/

Further reading: http://docs.versionpress.net/en/sync/cloning
and also http://docs.versionpress.net/en/sync/merging

WordPress plugin (with commercial Pro version): WP DB Migrate Pro.
https://wordpress.org/plugins/wp-migrate-db/
I use the Pro version for providing test systems for customers in my WooCommerce tickets.

WP DB Migrate Pro works smoothly and well. It allows you to selectively push and pull database data by tables. But there is no sync functionality available. Deliciousbrains are working on another solution they call ‘datahawk’.

WordPress plugin: WP-staging
https://wordpress.org/plugins/wp-staging/

Fastest site duplication I know of. It duplicates locally which is a big plus as you stay in the same environment. The developer is still working on a feature that allows you to push back changes.

WordPress plugin: WPSiteSync for Content
https://wordpress.org/plugins/wpsitesynccontent/

Briefly tested, no support for WooCommerce yet.

WordPress plugin: Gitium
https://wordpress.org/plugins/gitium/

I haven’t taken a look yet. Seems to cater to a different problem scenario.

WordPress plugin: WP Github Sync
https://wordpress.org/plugins/wp-github-sync/

I haven’t taken a look yet.

WordPress plugin: PushLive
https://wordpress.org/plugins/pushlive/

I haven’t taken a look yet. This one supports WordPress Multisite.

Codecanyon plugins
Yes I also looked there. The only thing I found were two ‘copy’ plugins, but nothing capable of sync.
https://codecanyon.net/item/wp-mirror/4069845
https://codecanyon.net/item/wp-remote-post-replicator/9306623

What is next?

Honestly I do not know. But I will keep my ear to the ground and post as soon as I have something new and viable.
Have I missed something out there? If yes, let me know in the comments.

FAQ

While I was working on my staging site my live site got new orders, that I do not want to overwrite / lose.
How do I push my staging site to live without loosing new orders?
How do I selectively push my data so I maintain new orders? 

As mentioned above WooCommerce uses no custom tables for storing products, customers and orders, but saves its data in the wp_post table along with all other posts. There is no selective table transfer possible. You would have to identify the WooCommerce data amidst the post data and then magically and seamlessly fit it into your live site while preserving / adapting post IDs correctly. Not happening (for now).

The solution to this is to use an import / export routine in addition to your deploy process.

  1. Export all orders / customers / products / all WooCommerce data from your current live site. It does not have to be all the data, you can of course set a date range for the export.
  2. Shutdown / block live site to prevent further orders.
  3. Push staging onto live overwriting it completely
  4. Import data from step 1 to new live site.

This will result in a fully updated live site with all current WooCommerce data on board.

Related Posts

Powered By Related Posts for WordPress

13 Replies to “How to sync WordPress / WooCommerce staging and production site. A current overview.”

  1. Thanks for the overview and the options, DB sync is indeed one of the hardest problems in WordPress.

    VersionPress currently supports vanilla WordPress sites and some simpler configurations. Generic 3rd-party plugin support is currently being worked on (issue #1036) and will be available in v4 later this year. WooCommerce is actually one of the plugins we’d like to test and support first – would you like to help us test it?

    Thanks,
    Borek

    1. Hi Borek, thanks for the comment and offer. I have followed the progress of VersionPress since it was only an idea. Therefore I will be happy to contribute.
      How can I help?

      1. When the plugin support is roughly ready, we’d like to get feedback on it and try to support some first plugins. Can I add you to that issue as a WooCommerce expert and keep you in the loop?

        1. Absolutely. I got the GitHub notification and will keep myself updated as best as I can. Very interested in following the progress.

          1. So, as I am in this particular boat of a woocom dev site and a live site.. is there any further progress on this project?

  2. Hi there. I use SiteGround hosting and have a WordPress Woocommerce store. I am able to make staging sites withe SiteGround, but my concern is that when I push my updated staging site to the live site, that it will overwrite the data concerning my store’s sales that were made while I was updating the staging version. How can I avoid that?

    1. Hi Celenie,

      You are correct in your assumption that pushing back changes from your staging site will overwrite the data on your live site.
      Other than the options discussed here, I have not found anything better yet.

      If the changes are not many and there is no option in this post that you like, I would simply apply them manually. I also like using selective database table migrations to move only the data I want. But that requires you to be able to clearly separate the changes you work on from the WooCommerce data.

  3. Hey Con,

    I’m curious if you have you thoroughly tested Stagecoach with a WP+WooCommerce site at this point, and if so, what your observations were.

    Many thanks,

    Eric

    1. Hi Eric,

      I have not yet, but I would be curious as well. If I find the time I’ll do just that and reach out to the team of WP-Stagecoach. This post can certainly use a follow-up at some point soon :).

      Many regards,
      Con

  4. WP All Export with WP All Import, is a great option for staging to prod sync issues. Since you can export just the needed post types, products and orders, can also deal with users as well. Since it supports WooCommerce.

Leave a Reply

Your email address will not be published. Required fields are marked *