How to set name of the wxr file when exporting blog data using wp-cli

By default (actually, you cannot change right now), when you export blog data usingWP-CLI, the wxr will be name as following:

myblogname.wordpress.2015.xml


1. Clone the wp-cli project:

$ git clone https://github.com/wp-cli/wp-cli.git

2. Install composer and install WP-CLI's dependencies:

$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer
$ cd /path/to/wp-cli/src/
$ composer install

3. Modify the get_filename_template function in /path-to-wp-cli-src/php/commands/export.php. For example, I want to name the exporting file after the blog's path: blog-1-path.xml

$ nano /path/to/wp-cli/src/php/commands/export.php
...
private static function get_filename_template() {
$export_file_name = get_bloginfo('url') . ".xml";
$export_file_name = str_replace("http://", "", $export_file_name);
$export_file_name = str_replace("/", "", $export_file_name);
if( is_multisite()) {
$export_file_name = str_replace("my.multisite.com", "", $export_file_name);
}
return $export_file_name;
}
...

4. Then run the export command to see the result

$ /path/to/wp-cli/src/bin/wp export --path=/path/to/wordpress/root --dir=/path/to/export/ --url=http://my.multisite.com/blog-1-path/


You will have a backup file names blog-1-path.xml. Pretty neat huh?