Data sync from production to non-production environments
Data syncs on WordPress VIP can only occur from production environments to non-production environments. Data syncs facilitate testing and QA of new features and allows teams to accurately reproduce and examine errors in a non-production environment.
Files uploaded to the production environment are made available to non-production environments in read-only mode by UnionFS. After a data sync, media file URLs on the target environment will automatically point to the shared files.
Prerequisites
- To initiate a data sync, a user must have at minimum an Org admin role or an App write role for that application.
- WordPress multisite environments that have sites created in addition to the root site (site ID 1) must create and maintain a config.yml file for the results of a data sync to work as expected.
Actions that occur during a data sync
The data sync operation is designed to not impact the production site in any way; all processing happens on the target environment:
- The target environment is protected via “maintenance mode”. This prevents access to the site while the data is being restored and manipulated, and ensures no changes can be made (and lost) during this time.
- The most recent backup from production is loaded into the target environment.
- Occurrences of the primary production domain in the database are replaced with the primary domain for the target environment. For example, if the production site domain is
example.com
and the target non-production site domain isexample-com-develop.go-vip.net
, then all instances ofexample.com
will be replaced withexample-com-develop.go-vip.net
in the target database after the sync. - Protected options are restored.
- The
wp vip data-cleanup datasync
CLI command is run for further cleanup. - The
vip_datasync_cleanup
hook can be used for custom cleanup of your application data during this step. - Jetpack is (re)connected.
- Caches are flushed.
- Maintenance mode is deactivated.
Running a data sync via the VIP Dashboard
Data syncs can be initiated in the VIP Dashboard. Once logged into the VIP Dashboard:
- Navigate to the “Data” link in the left-hand navigation menu.
- Choose the destination environment for the data sync at the top of the dashboard (e.g., “Develop”).
- Click on “Copy from Production”.
- Follow the prompts in the dashboard and click on the “Copy Data” button when ready.
Running a data sync via CLI
To run the following commands, VIP-CLI must first be installed on your local machine.
Step 1: Find the application name or ID you wish to sync
You can do this with the vip app list
command, which will give you back a list of apps. You want the name
or the id
.
Step 2: Initiate the sync
Run the sync command with the app name
, e.g. vip sync --app=my-app
, or the app id
, e.g. vip sync --app=000
. You will be prompted for the environment you wish to sync to, i.e. the target environment. You can get more information about sync command options by using the help parameter, i.e. vip sync --help
.
Protected options
The following options are protected during data syncs, meaning they are backed up on the child site before the sync and restored afterward. This is to prevent environment-specific configs from being shared between environments. It is not possible to extend or modify this list.
"WP Options" = [
'jetpack_options',
'jetpack_private_options',
'vaultpress',
'vip_jetpack_connection_pilot_heartbeat',
'wordpress_api_key',
'vip_search_index_versions',
'vip_search_global_index_versions',
];
// On multisites
"Site Meta" = [
'vip_search_global_index_versions',
];
Custom cleanup operations
The vip_datasync_cleanup
hook can be used for custom cleanup of application data (e.g., removing production API keys, performing brief data manipulation) after a data sync.
In this example the vip_datasync_cleanup
hook is used to delete the my_social_api_token
option on the non-production environment:
/**
* Run some custom cleanup after a migration.
*
* @uses vip_datasync_cleanup
*/
function my_action_vip_datasync_cleanup() {
// Safety first: Don't do anything in
// the production environment
if ( 'production' === VIP_GO_APP_ENVIRONMENT ) {
return;
}
delete_option( 'my_social_api_token' );
}
add_action( 'vip_datasync_cleanup', 'my_action_vip_datasync_cleanup' );
On a multisite, the cleanup hook is run individually on each subsite within that multisite.