How To Export WordPress From The Command Line CLI

Published Date Author: , Posted July 29th, 2011 at 2:03:03pm

Create a file called export.php in the wordpress top directory containing the following (remember to add the PHP tags at the top and bottom):

1
2
3
4
5
6
7
8
9
10
11
include 'wp-config.php';
include 'wp-admin/includes/export.php';
 
ob_start();
export_wp();
$file = ob_get_contents();
ob_end_clean();
 
$fh = fopen("wordpress-" . date('Y-m-d') . ".xml", 'w');
fwrite($fh, $file);
fclose($fh);
include 'wp-config.php';
include 'wp-admin/includes/export.php';

ob_start();
export_wp();
$file = ob_get_contents();
ob_end_clean();

$fh = fopen("wordpress-" . date('Y-m-d') . ".xml", 'w');
fwrite($fh, $file);
fclose($fh);

Comments reader  2 Reader Comments

Tim Walters - Gravatar

zombo.com/ Tim Walters said on April 9, 2012, 2:34 pm:

You are on the right track here but I’m pretty sure this will only work for a single blog. I need multisite support but I’m used to dealing with issues like this. Your approach has put me on the right track, so thanks!

erics - Gravatar

www.wyzaerd.com erics said on April 9, 2012, 2:37 pm:

Thanks very much for the feedback! If you happen to solve the multi-site issue, please come back and share it here…

Leave Your Comment  Leave a comment

All fields marked with "*" are required.