10up / MU-Migration

This WP-CLI plugin makes the process of moving sites from single WordPress sites to a Multisite instance (or vice-versa) much easier. It exports everything into a zip package which can be used to automatically import it within the desired Multisite installation.
MIT License
329 stars 47 forks source link

Error during import: db tables created but no site/files/plugin/theme #6

Closed NateWr closed 8 years ago

NateWr commented 8 years ago

This is a pretty cool tool, and even with the error I ran into saved me tons of time, thanks!

I ran the following on my single site:

$ wp mu-migration export all site.zip --plugins --themes --uploads

Then moved the zip over to my new server where the multisite is set up and ran this:

$ wp mu-migration import all site.zip

It spit out a bunch of MySQL errors:

crop@themeofthecrop-ubuntu-2gb-nyc3-01:/var/www/demo.themeofthecrop.com/htdocs$ wp mu-migration import all ~/plateup-site.zip 
Extracting zip package...
WordPress database error Table 'demo_themeofthecrop_com.wp_3_options' doesn't exist for query SELECT option_value FROM wp_3_options WHERE option_name = 'wp_3_user_roles' LIMIT 1 made by include('phar:///usr/local/bin/wp/php/boot-phar.php'), include('phar:///usr/local/bin/wp/php/wp-cli.php'), WP_CLI\Runner->start, WP_CLI\Runner->_run_command, WP_CLI\Runner->run_command, WP_CLI\Dispatcher\Subcommand->invoke, call_user_func, WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}, call_user_func, TenUp\MU_Migration\Commands\ImportCommand->all, TenUp\MU_Migration\Commands\ImportCommand->create_new_site, switch_to_blog, WP_Roles->reinit, get_option
WordPress database error Table 'demo_themeofthecrop_com.wp_3_options' doesn't exist for query SELECT option_value FROM wp_3_options WHERE option_name = 'blog_charset' LIMIT 1 made by include('phar:///usr/local/bin/wp/php/boot-phar.php'), include('phar:///usr/local/bin/wp/php/wp-cli.php'), WP_CLI\Runner->start, WP_CLI\Runner->_run_command, WP_CLI\Runner->run_command, WP_CLI\Dispatcher\Subcommand->invoke, call_user_func, WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}, call_user_func, TenUp\MU_Migration\Commands\ImportCommand->all, TenUp\MU_Migration\Commands\ImportCommand->create_new_site, sanitize_text_field, wp_check_invalid_utf8, get_option
WordPress database error Table 'demo_themeofthecrop_com.wp_3_options' doesn't exist for query SELECT option_value FROM wp_3_options WHERE option_name = 'blogname' LIMIT 1 made by include('phar:///usr/local/bin/wp/php/boot-phar.php'), include('phar:///usr/local/bin/wp/php/wp-cli.php'), WP_CLI\Runner->start, WP_CLI\Runner->_run_command, WP_CLI\Runner->run_command, WP_CLI\Dispatcher\Subcommand->invoke, call_user_func, WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}, call_user_func, TenUp\MU_Migration\Commands\ImportCommand->all, TenUp\MU_Migration\Commands\ImportCommand->create_new_site, install_blog, get_blogaddress_by_id, get_blog_details, get_option
WordPress database error Table 'demo_themeofthecrop_com.wp_3_options' doesn't exist for query SELECT option_value FROM wp_3_options WHERE option_name = 'siteurl' LIMIT 1 made by include('phar:///usr/local/bin/wp/php/boot-phar.php'), include('phar:///usr/local/bin/wp/php/wp-cli.php'), WP_CLI\Runner->start, WP_CLI\Runner->_run_command, WP_CLI\Runner->run_command, WP_CLI\Dispatcher\Subcommand->invoke, call_user_func, WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}, call_user_func, TenUp\MU_Migration\Commands\ImportCommand->all, TenUp\MU_Migration\Commands\ImportCommand->create_new_site, install_blog, get_blogaddress_by_id, get_blog_details, get_option
WordPress database error Table 'demo_themeofthecrop_com.wp_3_options' doesn't exist for query SELECT option_value FROM wp_3_options WHERE option_name = 'post_count' LIMIT 1 made by include('phar:///usr/local/bin/wp/php/boot-phar.php'), include('phar:///usr/local/bin/wp/php/wp-cli.php'), WP_CLI\Runner->start, WP_CLI\Runner->_run_command, WP_CLI\Runner->run_command, WP_CLI\Dispatcher\Subcommand->invoke, call_user_func, WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}, call_user_func, TenUp\MU_Migration\Commands\ImportCommand->all, TenUp\MU_Migration\Commands\ImportCommand->create_new_site, install_blog, get_blogaddress_by_id, get_blog_details, get_option
WordPress database error Table 'demo_themeofthecrop_com.wp_3_options' doesn't exist for query SELECT option_value FROM wp_3_options WHERE option_name = 'home' LIMIT 1 made by include('phar:///usr/local/bin/wp/php/boot-phar.php'), include('phar:///usr/local/bin/wp/php/wp-cli.php'), WP_CLI\Runner->start, WP_CLI\Runner->_run_command, WP_CLI\Runner->run_command, WP_CLI\Dispatcher\Subcommand->invoke, call_user_func, WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}, call_user_func, TenUp\MU_Migration\Commands\ImportCommand->all, TenUp\MU_Migration\Commands\ImportCommand->create_new_site, install_blog, get_blogaddress_by_id, get_blog_details, get_option
Importing Users...
Importing tables...
Updating post_author...
Error: Invalid input file
crop@themeofthecrop-ubuntu-2gb-nyc3-01:/var/www/demo.themeofthecrop.com/htdocs$ ls
index.html              wp-blog-header.php    wp-load.php
index.php               wp-comments-post.php  wp-login.php
license.txt             wp-config-sample.php  wp-mail.php
mu-migration1461340848  wp-content            wp-settings.php
readme.html             wp-cron.php           wp-signup.php
wp-activate.php         wp-includes           wp-trackback.php
wp-admin                wp-links-opml.php     xmlrpc.php

I may have made a mistake in that I didn't re-map the domain name when I ran the import command. When I realized, I popped into the wp_blogs table and updated the record there. The site then appeared in my list of sites, and from there it was fairly easy to run a wp search-replace command to update the URLs properly.

However, none of my plugins, themes or files transferred over. I was able to work it all out by moving files from the mu-migration146134970848 directory it created in my wp root.

But I'm wondering if you have any idea what went wrong. I have two more sites to do in the coming weeks so would love to iron out any quirks with my setup if needed.

Thanks, this is a huge time saver for me!

nicholasio commented 8 years ago

Thanks for the report.

Can you tell me which version of wp-cli and WordPress you're using and the type of your multisite installation (subdomain or subdirectory).?

These SQL errors are coming from the create_new_site() method, when trying to install the newly created site.

The theme, plugins and uploads did't get transferred over due to an error on the update post_author routine, which couldn't find for some reason the mapping file and then exited the script execution. Can you check if there's a users_map.json in the mu-migration1461340848 dir?

NateWr commented 8 years ago

Source and destination: WP-CLI 0.23.0 WP 4.5

Source: Apache

Destination: Subdirectory multisite nginx

There's no users_map.json in the mu-migration* dir. I've got csv, json and sql files named mu-migration-*<site_slug>.<ext>.

I'm in the UK so clocking off for the day but do let me know if I can help provide any more diagnostic info or run any tests for you.

nicholasio commented 8 years ago

Ok, those SQL errors aren't the problem, they are harmless (but I'll fix them). Your only problem is that the import users routine didn't create a file required by the update_author method. How many users do you have in the single site? Were all of them transferred over?

NateWr commented 8 years ago

There was just the one user. Our old friend admin. :)

It looks like that user was not transferred over and it's caused some issues with the Author metabox on the Edit Post page. Luckily, none of the sites I'm working on now display author info so it's not really a big deal.

nicholasio commented 8 years ago

Thanks for the info @NateWr.

I know what went wrong and I'll work to patch this either today or over the weekend. You had this problem because no user had been transferred over (because there's also an admin user on your multisite install probably and thus no mapping table - the json file - had been created).

nicholasio commented 8 years ago

Hi @NateWr,

I have pushed a new version to master (which automatically goes to wp-cli package manager). Can you update to the latest version and try again?

The new version is 0.2.1 and you can check with: wp mu-migration info (if you receive an error you're still on the old version).

nicholasio commented 8 years ago

Hey @NateWr were you able to test the new version?

NateWr commented 8 years ago

Sorry @nicholasio, I've been away on a work trip the last week and I'm still getting caught up. I plan to run more migrations later this week or early next week and will definitely give you an update as soon as I can. I appreciate how quickly you responded to the report.

NateWr commented 8 years ago

Hi @nicholasio, I updated mu-migration and ran the export script again:

$ wp mu-migration export all ~/site.zip --plugins --themes --uploads

I took a look at the ~/site.zip file and there's no users_map.json file in it. Does that sound right? I haven't yet tried to import it (just about bedtime here) but I thought I'd check to see if that looked right to you.

nicholasio commented 8 years ago

That's correct, the users_map.json is created only when importing because it needs to know the new users ids.

NateWr commented 8 years ago

Ok sorry for the noise. I'll let you know how the import goes.

NateWr commented 8 years ago

Mostly smooth sailing. The import went great and very quickly. Here's the output:

crop@themeofthecrop-ubuntu-2gb-nyc3-01:/var/www/demo.themeofthecrop.com/htdocs$ wp mu-migration import all ~/plateup-site.zip --new_url=demo.themeofthecrop.com/plateup
Extracting zip package...
Importing tables...
WordPress database error Duplicate entry 'wp_4_user_roles' for key 'option_name' for query UPDATE `wp_4_options` SET `option_name` = 'wp_4_user_roles' WHERE `option_name` = 'wp_user_roles' made by include('phar:///usr/local/bin/wp/php/boot-phar.php'), include('phar:///usr/local/bin/wp/php/wp-cli.php'), WP_CLI\Runner->start, WP_CLI\Runner->_run_command, WP_CLI\Runner->run_command, WP_CLI\Dispatcher\Subcommand->invoke, call_user_func, WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}, call_user_func, TenUp\MU_Migration\Commands\ImportCommand->all, TenUp\MU_Migration\Commands\ImportCommand->tables
Moving files...
Moving Plugins...
Moving export-bookings-for-rtb to plugins folder
Moving wpremote to plugins folder
Moving custom-fields-for-rtb to plugins folder
Moving akismet to plugins folder
Moving shepherd to plugins folder
Moving food-and-drink-menu-pro to plugins folder
Moving wordpress-seo to plugins folder
Moving mailchimp-for-rtb to plugins folder
Moving Uploads...
Moving Themes...
Moving twentyfifteen to themes folder
Importing Users...
Updating post_author...
Flushing rewrite rules...
Removing temporary files....
Success: All done, your new site is available at http://demo.themeofthecrop.com/plateup. Remember to flush the cache (memcache, redis etc).

I notice that when I look at Posts or Pages in the wp admin table lists, I see the author nate. But when I open the Post or Page for editing, there's an empty author metabox (no select dropdown). This may be because the author ID is 1 in the source site, but the names/emails are different in the source/destination sites.

This is not a problem for my purposes, just a heads up. Thanks for the quick fix, this tool is amazing.

nicholasio commented 8 years ago

Thanks @NateWr for the heads up, Do you have any kind of caching on the sever? like Redis or Memcache? they can cause some inconsistencies like this after running the script, if so, try flushing the cache.

Anyway I'll take a look at this.

NateWr commented 8 years ago

No caching running as far as I'm aware, however this is my first go on an nginx server and I used EasyEngine to get some initial things set up. So it's entirely possible there is something running that I'm unaware of. :)

nicholasio commented 8 years ago

Ok, I'm gonna close this out. If I find a bug with the users I'll open a separate issue.