Skip to content

Import databases

Prerequisite

Export a SQL file from a non-VIP WordPress install

In order to migrate existing database content to VIP, an SQL file must be exported from a current WordPress site. Recommended methods for exporting a WordPress SQL database:

  1. Install a third-party plugin designed to export WordPress database content.
  2. Run a  mysqldump command in a command line interface. For example:
mysqldump --add-drop-table --hex-blob --no-create-db --quote-names -h dbhost -u user -p dbname --default-character-set=utf8mb4 --result-file=dbname-full.sql

Caution

Exports from phpMyAdmin are not compatible with VIP’s import tooling.

Check that the database is a valid SQL file

Verify that the SQL database file is correctly formatted for import with the VIP-CLI command:
vip import validate-sql <path/to/file.sql>

The following example shows the command and the output when using VIP-CLI to validate a file named file.sql:

$ vip import validate-sql file.sql 
Finished processing 15 lines.

✅ SET @@SESSION.sql_log_bin statement was found 0 times.
✅ TRIGGER statement was found 0 times.
✅ DROP DATABASE statement was found 0 times.
✅ USE <DATABASE_NAME> statement was found 0 times.
✅ ALTER USER statement was found 0 times.
✅ DROP TABLE was found 1 times.
✅ CREATE TABLE was found 1 times.
 - wp_ prefix tables found: 1 
'siteurl','https://example.com'
✅ ENGINE != InnoDB was found 0 times.

Multisite network database imports

Database structure for a WordPress multisite differs from the database structure of WordPress single site. In order to import a database to a VIP WordPress multisite network, the database must be exported from a WordPress multisite.

If the origin WordPress site is a single site, the database will need to be converted to a multisite database prior to import. A working version of a VIP app on a local development environment set up as multisite is a helpful tool for migrating WordPress single sites into a multisite.

Requirements for importing a database to a VIP multisite network:

  • The database must have been exported from a WordPress multisite.
  • If importing the database for an entire multisite network, ensure that the export has the wp_site and wp_blogs tables.
  • If importing tables for a specific subsite, ensure the table prefixes match the intended destination site ID (e.g., tables prefixed wp_3_ will be imported to subsite 3). Table prefix values will be visible in the confirmation output of the import command.
  • If importing a selection of tables for one or more subsites, the database export should include only the tables for those subsites.
Screenshot of returned messages and warnings when running a database import to a WordPress multisite

Import database files with VIP-CLI

Caution

Importing a SQL database to a VIP site will replace data on the site for any SQL tables included in the import file. Pre-existing data that is overwritten by an imported table will be gone.

Prior to running any import commands, confirm all items in this checklist:

  • The database for import is a valid SQL file.
  • For unlaunched sites the database must be smaller than 100GB in size.
  • For launched sites the database must be smaller than 350MB in size.
  • Before importing the database file to a VIP environment, perform a test import into an empty local WordPress development environment to ensure that the prepared database provides expected import results.

If the database for import does not meet the above requirements, create a VIP Support ticket requesting assistance with the import and include a downloadable link for the database file.

Import SQL

Import a SQL database to an environment with the vip import sql VIP-CLI command.

Refer to the help menu for a full list of commands, options, and examples.

vip import sql --help

VIP-CLI command examples

For demonstration purposes, the <app-alias> value mytestsite and the <env> value production are used in the VIP-CLI command examples below. Read more about how to target environments in VIP-CLI commands.

Example command for importing a SQL database named “file.sql“, where the command is run from within the same local directory as the file:

vip import sql @mytestsite.production file.sql

Use search and replace to update domain name values

If the database for import contains domain name values that do not match the VIP destination site’s domain name, a search and replace operation will be needed during import.

  • The domain name value for an unlaunched VIP site is typically a convenience domain (Example: example.go-vip.net).
  • Search and replace values are separated by a comma only. There are no spaces between the values.

The following example shows the values as they would need to appear in order to search for the domain http://localhost in a database that was exported from a local machine, and replacing it on import with the convenience domain https://example.go-vip.net for an unlaunched VIP environment:

vip import sql @mytestsite.production file.sql --search-replace="http://localhost,https://example.go-vip.net"

Example command for a database import to a WordPress multisite, also demonstrating multiple search-replace operations:

vip import sql @mytestsite.production file.sql --search-replace="http://localhost,https://example.go-vip.net" --search-replace="example2.com,example.go-vip.net/subdir"

Check the status of an import

If an import is currently running, the output from the vip import sql status command will be for the currently running import. If an import is not currently running, the output will be for the import that ran most recently. The Audit Log panel, located in the Organization view of the VIP Dashboard, can provide insight into when an import was requested.

Output from the status command lists the series of steps executed during an import, and displays a progress indicator for each step:

  • Pending:
  • Success:
  • Failed:

An overall status report on the import process appears below the listed import steps. The Status: field will display either Running, Success or Failed.

$ vip import sql status @mytestsite.production
=============================================================
Checking the SQL import status for your environment...
✓ Performing Search and Replace
✓ Uploading file
✓ Queueing Import
✓ Import preflights
✓ Downloading file from s3
✓ Uncompressing gzip
✓ Checking md5 hashes
✓ Backup db
✓ Importing db
✓ Validating db
✓ Update wp blogs table
✓ Update primary domain

=============================================================
Status: Success ✓ imported data should be visible on your site mytestsite.go-vip.net.
Site: mytestsite (PRODUCTION)
SQL Import Started: 07/01/2022, 1:14:54 pm (2022-01-07T02:14:54.000Z)
SQL Import Completed: 07/01/2022, 1:19:31 pm (2022-01-07T02:19:31.000Z)
=============================================================
Import step Operation performed
Performing Search and ReplaceThe search and replace operation(s) running on the file if a search and replace was specified in the import command.
Uploading fileFile compression and uploading to S3.
Queueing ImportQueueing the import job in the system.
Import preflightsPreparing the import job is in the system.
Downloading file from s3Downloading the file from S3.
Uncompressing gzipUncompressing the file.
Checking md5 hashesValidating the integrity of the file and its data.
Backup dbCreating a backup of the current state of the database.
Importing db**Importing the SQL file to the site.
Validating dbValidating the post-import state of the database with the imported data.
Update wp blogs tableUpdating the wp_blogs table: For a WordPress multisite environment, this is the database table that identifies a subsite in its network.
Update primary domainUpdating the primary domain: For a WordPress multisite environment, if the process determines that the wp_site table contains a different domain at the first row than the primary domain that is currently set in VIP.

**If an import fails at the Importing db step:

  • An unlaunched environment’s database automatically rolls back to the backup taken prior to the import job.
  • A launched environment will be locked against any additional import attempts and needs to be reset by VIP Support in order for a new import to be attempted.

Failures can occur due to an invalid SQL file, or if there is an error present in the file. If the import fails, the Restore db step is returned in the status output.

Considerations

  • It is possible for the import process to complete successfully, but for other conflicting errors to prevent the site from loading properly (e.g.- PHP errors in the theme). If the results of an import are not as expected after the process has completed, the process can be re-tried.
  • Non-production environments will go into maintenance mode during a SQL import. This will block users from making database updates (e.g., creating or editing posts, changing site settings) for the duration of the import process.
  • Once a database import into a VIP environment has completed, site testing is recommended to ensure that the results match the expectations of the import.

Protected options

The following options are protected during SQL imports, meaning they are backed up beforehand and restored afterward. This is to help prevent overwriting or accidentally sharing environment-specific configs. 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_sqlimport_cleanup hook can be used for custom cleanup or changes of application data after an import. Some examples of cleanup operations include switching out production API keys, or performing brief data manipulation. It is not ideal to do any longer-running operations here as it keeps the site under maintenance mode until it import is completed. Instead, consider registering a one-time cron event on this hook, to do something immediately afterwards via cron.

Last updated: May 12, 2022