Introducing how to export and backup WordPress database blog posts and content from the command line via SSH connection using the wp export command.
wp export | WP-CLI Command | WordPress Developer Resources
Navigate to the WordPress installation directory from the command line via SSH, and simply run the wp export command to easily export and backup.
$ wp export
Starting export process...
Writing to file /home/yuis/yuis-programming.com/public_html/_hoge/yourblog.wordpress.2021-11-03.000.xml
Success: All done with export.
An .xml file was output.
Let’s take a look at the file.
$ file yourblog.wordpress.2021-11-03.000.xml
yourblog.wordpress.2021-11-03.000.xml: XML 1.0 document, UTF-8 Unicode text, with very long lines
The file size was approximately 5MB.
$ du -h yourblog.wordpress.2021-11-03.000.xml
4.6M yourblog.wordpress.2021-11-03.000.xml
As a side note, since the output data should be placed in the public directory, there is a risk that hackers or third parties could download the file if the file path becomes known.
Exported files may contain sensitive data (such as unpublished posts), so it’s a good idea to move the exported file to a location that is not a public directory.
$ mv yourblog.wordpress.2021-11-03.000.xml ~/data/