Skip to content

Import Site Tab

Chris Chasm edited this page Jan 8, 2021 · 8 revisions

screenshot

Instructions for Migrating to the Multisite Disciple Tools system

Because importing users into a new multisite changes the user ids we need a custom strategy to update ids while importing the data

This strategy has you import the data into temporary tables so can replace the ids before copying to their final destination.

  • Stage 1 is exporting and importing the database.
  • Stage 2 is running the migration

To export from a single site:

mysqldump [DB_NAME] > dump.sql

Replace [DB_NAME] with the name of your database. Ex: local

To export from a multiste:

Let's import a subsite with id 15 and database prefix wp_ from a multisite.

Export your sql file from you old site:

We'll only extract the users and usermeta that belong to the subsite.

Replace 15 with the id of your existing subsite. Replace "wp_" if you instances uses another prefix

Export the subsite specific tables

mysqldump [DB_NAME] $(mysql -D [DB_NAME] -Bse "show tables like 'wp\_15\_%'") > dump.sql

Extract the users

mysqldump [DB_NAME] wp_users --lock-all-tables --where "ID in (SELECT user_id from wp_usermeta um where um.meta_key = 'wp_15_capabilities' )" >> dump.sql

Extract the usermeta

mysqldump [DB_NAME] wp_usermeta --lock-all-tables --where "user_id in (SELECT user_id from wp_usermeta um where um.meta_key = 'wp_15_capabilities' ) AND meta_key LIKE 'wp_15_%'" >> dump.sql

Replace domain names

Ex domain: disciple.tools -> dtorg.local sed -i -e 's|https://disciple\.tools|http://dtorg.local|g' -e 's|disciple\.tools|dtorg.local|g' dump.sql

Prepare the sql.

We are going to import this sql file into the database creating new temporary tables starting with dt_tmp_migration

So we want to replace wp_ (or your prefix) with dt_tmp_migration sed -i -e 's|wp_|dt_tmp_migration_|g' dump.sql

Import the sql

Backup your database

Now on the server you want to import dump.sql into the database: mysql [DB_NAME] < dump.sql

Delete the dump.sql file so it is not laying around.

User the Site Naming and Site ID Substitution Tools with the Prepared SQL