That was the question.
Have you ever split a multisite? If so, how?
I wrote about Breaking Up Multisite before, but this was more specific.
Yes. And it’s a funny story.
I should preface the story with the reminder that in general when someone asks me how to do it, I casually mention that they can’t pay me enough to do it. This turned out to be inaccurate, as I was paid to do it. One of my first tasks at DreamHost was to take three separate sites and turn it into a two-site Multisite network. Two blogs were merged into one, then the new site was moved to Multisite. We did that with the export/import tools in WordPress. Fast-forward two years (my how time flies, Simon!) and now I’m asked to un-do it. But they only want site #2 now. The main site is being deleted.
I was actually glad, since this gave me a chance to handle the site properly and upgrade it correctly. I could clean out the old posts and content, re-sync users, tighten security, and undo the nightmare that was our old process. Plus the exercise of unraveling would give me more experience in WordPress shenanigans. And finally, it answered the question of how much you would have to pay me in order to do this (answer: more than most people would).
It started out as a massive 30 step process, but after running through it a few times, I was able to speed it up into five, simple, sections. I make use of WP-CLI here, but if you don’t have it you’ll want to get interconnectit’s search and replace tool to save you a migraine.
Bring it Local
I use Vagrant and I made example.dev for this.
Then I just copied down all the files from example.com/wp-content/blogs.dir/2/files/
to example.dev/wp-content/uploads-orig/
and did a database dump. Since I use WP-CLI, this was just a wb db export
command.
That was the full database, though, all 64megs of it, and I only wanted the second site. But we’ll get there in a second. I knew I had WP-CLI on my test box, but if I didn’t, I would have zipped the file in order to use phpMyAdmin (which would make it about 6megs). I’m lazy. I like GUIs. Either way, I imported the entire database to my new server.
I also made a new wp-config.php
file while I was at it, for multiple reasons. The one we were using did a check to see what domain you were on, and loaded different database params based on that. It was a cool bit of code, but it was unnecessary here. Making a new config file is easy (for me), and it ensured I had it clean and only set to a single install of WordPress. After all, I’m de-multisiting.
Fix the Tables
Of course, I had to clean that database. The first step was simple and I dropped all wp_FOO
tables except wp_users
and wp_usermeta
. That left me with all the wp_2_
tables.
Next I renamed wp_2_
to wp_
so I could have everything nice and orderly. But there’s a catch there, becuase there’s an option in my wp_options
table that has the name wp_2_user_roles
. Can you see what’s wrong? I need that to become wp_user_roles
and I need to update any usermeta.
Break out WP-CLI again and run this: wp search-replace "wp_2_" "wp_"
So nice. So easy. That actually took care of 100% of the issues with the table renames. Were I doing it manually, it would be time for tears in your beers.
Clean the Images
With WP-CLI this is a snap:
wp search-replace http://example.com/foldername/files/ http://example.dev/wp-content/uploads/ wp search-replace http://example.com/foldername http://example.dev wp search-replace wp-content/blogs.dir/2/files wp-content/uploads
I ran it like that for a reason. I like to do my searches in order of smallest catch to biggest, and this way it kept my possible gaffs to a minimum. I knew I had to fix all the images and post content, so it was safer this way.
Clean up Users, Themes, and Plugins
We had a lot of old, duplicate, users who had no posts or had left the project. I went over everyone’s permissions, dropped them down as low as I could, and removed half the admins. It’s just a good time for that.
Next I reinstalled themes and plugins. I could have just copied them down, but I reinstalled everything because I wanted to take the time to make sure they were all clean and the latest versions. This is also where I paused to do a security review of everything we had.
Move it Live
Well now we’re just moving WordPress like normal. Copy it all up via FTP, copy up the database, run a last search replace to change example.dev to the real, new, domain (which I don’t actually know yet know), and it’s done. If I use wp-cli again, this will be as simple as running this: wp search-replace example.dev newsite.com
All that extra work I did before pays off here.
The nice thing about this is that I could have done this and then keep the main site if I’d wanted to. I didn’t, but I could have easily deleted all the wp_2_
tables and just cleaned up the multisite stuff. The headache is I’d have to do this multiple times if I’d had, say, ten sites on the network and wanted to move them all. If that had been the case, I would have only exported the wp_2_
tables and the wp_users
and wp_usermeta
ones.
But yes. I have un-multi’d a site.
Comments
5 responses to “Mailbag: Have You Ever Split a Multisite?”
Have you ever tried the multisite functions of BackupBuddy (or a similar plugin) for this kind of task?
http://ithemes.com/codex/page/BackupBuddy_Multisite
@Jason Pelker: I have not, and for a very practical reason.
Asking a plugin to run a backup and deploy means I’m at the mercy of the PHP memory on my server. If I’m moving to a shared server, the odds are rather high that a medium to large site will choke. I have heard good things, but I think that in the case of what I was doing, it would have made it more complicated since iThemes’ plugin would have distanced me from the work I was doing. The way I did it, I knew where I was and what I was doing and, if it broke, I knew where.
I’ve made other migrations before and I think I’m missing a lot for not using wp-cli… I had much more work, more steps as I think you had, rather than if I used wp-cli.
Thanks for sharing! =)
@Renato Alves: wp-cli is a godsend. It’s the best WP tool in years.
Great stuff @Ipstenu
Thanks π