How Does WP STAGING Handles WordPress Migration?

Whenever you start the WP STAGING Pro push process, several steps and preparations are done in the background to ensure 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

Let me explain the difference between migrating files and database tables.

Migrate WordPress

WordPress stores most of its settings in a unique location called the database. This data is organized in so-called ‘tables.’  The same goes for most of the plugins. They store the settings in this database.
The plugins 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 copying it, just as you copy files on your local computer.

Copy file data

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.

Simple Database Explanation

To understand it better, I will explain it with an analogy.

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

What is a database? Migration analogy explanation
Database Analogy

The apartment is the database; the types of furniture are the database data organized in so-called tables. You can arrange the furniture/table data but 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 contains the new /updated plugin, or select all folders.
  4. Unselect all database tables

Start the push process…
Done!

WordPress Migration

When you visit the live site, you will see that the plugin has been updated, and you will copy the plugin files to it.

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

This ensures that no database data is copied from the staging site to the live site, and no settings, orders, comments, or other custom data are overwritten on the live site.

What If I need to copy the theme or plugin settings?

If you want to migrate all of the staging site data, including plugin or theme settings, you need to copy the data from the database to the live site—remember our furniture?

Technically, this isn’t very easy. Getting the data from the database and copying it to the live site’s database tables is insufficient. It’s also necessary to perform complex searches and replace string operations on the data before copying it to the live site. This is complex because WordPress stores a lot of its data as serialized data.

A Search & Replace Example:

All links that contain the path to the staging site must be converted before they can be used on the live site:

https://hostname.com/stagingsite

turns into

https://hostname.com

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

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_options which is used by the live WordPress site.

Whenever you decide to push all or only particular database tables from the staging site to the 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 their names are prefixed with wpstgtmp_.
    E.g., the table wpstg(0)_options 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 plugins and theme settings are migrated to the live site.

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

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

Updated on July 23, 2024