[GTALUG] Selectively restoring WordPress posts from old SQL dump

Myles Braithwaite me at mylesbraithwaite.com
Thu Mar 30 09:25:15 EDT 2017


William Witteman via talk wrote:
> I have a bunch of WordPress blogs sharing a database, which seemed
> like a good idea at the time.
> 
> Now I have a bunch of posts that were overwritten at *some* time in
> the past by bad data, but my backups are good.
> 
> My backup testing works perfectly well for complete replacement, but I
> don't want to do that - I want to cherry-pick for one blog of several,
> and only replace posts that existed in November with the same IDs in
> today's database, but leave everything else alone.
> 
> Does anyone have any thoughts?

When I have to do a similar process (moving a WordPress site from
staging to production), I use the plugin [WP Migrate DB][0]. The free
version does exactly what it says.

If you don't want to use that plugin. How is your data stored in the
MySQL database? My assumption is it's a bunch of tables with different
prefixes (i.e. site1_posts, site2_posts, etc). You can use these two
commands:

$ mysql -N information_schema -e "select table_name from tables where
table_schema = 'change-me-to-database-name' and table_name like
'site1_%'" > site1_tables.txt

$ mysqldump change-me-to-database-name `cat site`_tables.txt` >
site1_dump.sql

[0]: <https://en-ca.wordpress.org/plugins/wp-migrate-db/>


More information about the talk mailing list