I came across an issue with a client site the other day where they had multiple WordPress Multisite installs each with hundreds of sub-sites on each install. Due to limitations with the hosting each install needed to only contain 100 subsites or less else there would be issues with issuing SSL certificates via LetsEncrypt.

In order to accomplish this, they would need to export the subsites one by one and then import them into other Multisite installs that had fewer subsites active on them, which as you could imagine would take a very long time to do by hand.

I created the following shell scripts that utilized the WP-CLI add-on that 10up had created to automate the process. The first script is run in the root directory of the WordPress install that you are wanting to export from. It will cycle through each site and create a zip file within a directory that I created called sites. Each zip is a complete export of the site including images, plugins, themes, and the database and are all saved as their primary domain.zip eg shelbydenike.com.zip

Export script

#/bin/bash # Requires: https://github.com/10up/MU-Migration version="2020.02.09.0" # Get all sites as csv output SITES="$(wp site list --fields=blog_id,domain --format=csv --allow-root|sed -n '1!p')" echo "Multisite Exporter" echo "Version:" $version echo "Starting multisite export..." while IFS= read -r SITE; do # Get Blog ID and Domain ID="$(echo $SITE | cut -d',' -f1)" DOMAIN="$(echo $SITE | cut -d',' -f2)" # Echo output echo "--------" echo "Blog ID:" $ID echo "Domain:" $DOMAIN # Create exported site wp mu-migration export all sites/$DOMAIN.zip --blog_id=$ID --plugins --themes --uploads done <<< "$SITES"

Once you have a directory full of all of the exported sites you can then can organize them so that you can import them on to the other multisite instances.

Import script

#/bin/bash # Requires: https://github.com/10up/MU-Migration version="2020.02.09.0" echo "Multisite Importer" echo "Version:" $version echo "Starting multisite import..." # Loop through export and import for ZIP in sites/*.zip ; do echo "Import File:" $ZIP wp mu-migration import all $ZIP done

I am hoping that in the future 10up will release and update to their add-on so external scripts like this will not be needed. If you find this useful, by all means send me a coffee 🙂 or if you are unsure on how to get all this working or need help, I am always for hire so please contact me to discuss!