5

I'm looking for some extra information about an mu site (--url) when attempting to export from a remote server to my local testing environment.

One requirement for migration is the existing blog_id and database prefix. Using those I can do a search/replace on the exported.sql for <wp-prefix>_<blog_id>_ to slot it into the correct db table on import.

Search and Replace

printf "%s" "$(sed "s/$blog_id_old/$blog_id_new/g" <<< "$(gunzip < $input)")" > $output;

Is there a better way to get the blog_id here? And can I get more information like the table prefix without running eval?

Blog ID

blog_id=$(wp eval --url=http://domain.com/site-name/ 'echo get_current_blog_id();');

DB Prefix

prefix=$(wp eval --url=http://domain.com/site-name/ 'global $wpdb; echo $wpdb->prefix;')

Thanks.

5
  • From a quick look there doesn't seem to be. Both of these depend on global vars, which have no dedicated command to access (I think) like options do.
    – Rarst
    Commented Aug 16, 2016 at 18:15
  • Do you think there should be a command for site or DB information?
    – jgraup
    Commented Aug 16, 2016 at 18:19
  • That is probably better aimed at WP CLI developers. :)
    – Rarst
    Commented Aug 16, 2016 at 18:20
  • It seems like this is the only good place to talk about it now. wp-cli.org/blog/support-policy.html hopefully some of the developers are on here. I don't mind making a PR if it doesn't feel too much like a loan wolf request.
    – jgraup
    Commented Aug 16, 2016 at 18:23
  • 1
    I am aware of the post, but hardly anything we can do here if it's something WP CLI just doesn't seem to do. And its developers is whose opinion on PR would matter, unlike us. :) I see no harm in bringing that on issue tracker there, especially if it is something you are willing to develop and contribute.
    – Rarst
    Commented Aug 16, 2016 at 18:26

1 Answer 1

0

You can use the wp db prefix command with the --url argument to determine the prefix for that particular site. If you need to determine the urls still, maybe consider using something like the wp site list command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.