Print

How Does WP Staging Handles WordPress Migration?

Whenever you start the WP Staging Pro push process, several different steps and preparations are done in the background to make sure that migrating the data from the staging site does not break your live site.

There are two things you need to differentiate when you start migrating the staging site:

  • Migration of file-based data
  • Migration of database tables

So wait, you are talking about file and database tables.
What is the difference?

WordPress stores most of its settings in a special location called the database. This data is organized in so-called ‘tables’.  Same goes for most of the plugins. They store the settings in this database.
The plugins itself are based on text files (like a text document) and are separated from the database and its tables.

A file can be transferred from one location to another by just copying it like you copy files on your local computer.

The content and data of the database can be accessed and requested by plugin files but the database itself can not be copied to another location like you would do it with a file.

To understand it better I am going to explain it with an analogy

You live in an apartment or house.
In that apartment you have furnitures which you can place wherever you want:

What is a database?
Database Analogy

The apartment is the database, the types of furniture are the database data organized in so-called tables. You can arrange the furnitures/ tables data but you can clearly not move the apartment/database to another location. At least not without extremely technical challenges and much bigger machines;)

Let’s have a real case example – Push a Plugin

You were installing a new plugin or did an update for an existing one on the staging site. If you just updated the plugin and did not change any of its settings it’s sufficient to copy over the plugin files to the live site by following the steps below:

  1. Go to WP Staging > Sites / Start
  2. Click on the Push button
  3. Select  the plugin folder that contain the new /updated plugin or just select all folders.
  4. Unselect all database tables

Start the push process…
Done!

When you visit the live site you will see that the plugin has been updated there by just copying the plugin files to the live site.

Why is it often helpful to copy plugin and theme files only or to exclude certain database table from migration?
Think about woocommerce shop orders or user comments on your website.
It’s likely that there are new comments or orders made after creating a staging site. To prevent overwriting of these data transactions, WP Staging allows you to exclude certain tables before executing the migration process.

Doing it that way ensures that no database data is copied from the staging site to the live site. That ensures that no settings, orders, comments or any other custom data are overwritten on the live site.

What If I need to copy theme or plugin settings?

If you like to migrate all of the staging sites data including plugin or theme settings then you need to copy the data from the database to the live site – remember our furniture?

Technically, this is very complicated. It’s not enough to get the data from the database and copy it to the database tables of the live site. It’s also necessary to do a complex search & replace string operations on the data before copying it to the live site. Complex, because WordPress is storing a lot of its data as serialized data.

A Search & Replace Example:

All links on which are containing the path to the staging site must be converted before they can be used on the live site:

https://host.com/stagingsite

turns into

https://host.com

There are dozens of similar and more complicated operations necessary before the staging site data can be used for the live site. Explaining every step is out of scope for this article and not necessary to understand the process at all.

The important thing for you to know is that WP Staging handles all those search & replace operations automatically for you!

So, back to our pushing the database example.

In that example, I am demonstrating what is happening to the single database table wpstg_options when we migrate it to the database table wp_content which is used by the live WordPress site.

Whenever you decided to push all or only particular database tables from the staging site to live site – move furniture from one room into another – the following is happening in subsequent order:

  1. All staging tables are copied to new tables and its names are prefixed with wpstgtmp_.
    E.g. the table wpstg(0)_content is renamed to wpstgtmp_options
  2. Several search & replace operations are running on that newly created database table wpstgtmp_options
  3. The live table wp_options is copied as wpstgbak_options for backup purposes in case something goes wrong. So we can recover the live site anytime with that table.
  4. wpstgtmp_options is replacing wp_options

That’s it. After reloading your live site you will see that all plugin and theme settings are migrated to the live site.

I hope this article gives you a good overview of how WP Staging is working behind the scenes.

If you like this article please share it with your friends and colleagues.