A Few Lines of SQL: Cloning Blogs In MU

The following SQL is what I used to clone the content from one blog in MU to another for testing. It’s probably useless to anybody but me.

Anybody who can’t figure out from the code that wp_8_posts is the source table and wp_13_posts is the destination probably shouldn’t try to use the code, as data will be lost.

Clone the content from one MU blog into another:

TRUNCATE TABLE wp_13_posts;
INSERT INTO wp_13_posts SELECT * FROM wp_8_posts;

TRUNCATE TABLE wp_13_postmeta;
INSERT INTO wp_13_postmeta SELECT * FROM wp_8_postmeta;

TRUNCATE TABLE wp_13_terms;
INSERT INTO wp_13_terms SELECT * FROM wp_8_terms;

TRUNCATE TABLE wp_13_term_taxonomy;
INSERT INTO wp_13_term_taxonomy SELECT * FROM wp_8_term_taxonomy;

TRUNCATE TABLE wp_13_term_relationships;
INSERT INTO wp_13_term_relationships SELECT * FROM wp_8_term_relationships;

TRUNCATE TABLE wp_13_bsuite4_search;
INSERT INTO wp_13_bsuite4_search SELECT * FROM wp_8_bsuite4_search;

TRUNCATE TABLE wp_8_scrib_harvest;

Clone a few options:

DELETE FROM wp_13_options
WHERE option_name IN ( "sidebars_widgets" )
OR option_name LIKE "scrib%"
OR option_name LIKE "widget%";

INSERT
INTO wp_13_options (option_name, option_value, autoload)
SELECT option_name, option_value, autoload
FROM wp_8_options
WHERE option_name IN ( "sidebars_widgets" )
OR option_name LIKE "scrib%"
OR option_name LIKE "widget%";

Delete revisions from the post table and remove the post_content from Scriblio book catalog records:

DELETE FROM wp_13_posts
WHERE post_type = 'revision'
AND (
	ID IN (
		SELECT object_id
		FROM wp_13_term_relationships
		WHERE term_taxonomy_id = 271871
	);
	OR post_parent IN (
		SELECT object_id
		FROM wp_13_term_relationships
		WHERE term_taxonomy_id = 271871
	)
);

UPDATE wp_13_posts
SET post_content = ''
WHERE ID IN (
	SELECT object_id
	FROM wp_13_term_relationships
	WHERE term_taxonomy_id = 271871
);

OPTIMIZE TABLE wp_13_posts;

The term_taxonomy_id is the ID of the catalog record category. The OR clause in the revision deletion code shouldn’t be necessary, but I actually matched a few extra records in my tests (I will quietly ignore the problems associated with the inconsistency this suggests…. Carry on, this is not the bug you are looking for).

Finally, restart, invalidate, or otherwise clear your object cache.