1. Home
  2. Enhance Panel
  3. WordPress Command Line
  4. How to back up and restore your WordPress database with WP-CLI

How to back up and restore your WordPress database with WP-CLI

Your WordPress database holds your posts, pages, settings and users. WP-CLI makes it easy to save a copy before you make changes, and to put it back if you need to.

New to WP-CLI? Start with getting started with WP-CLI, which shows you how to connect and get to your website’s folder.

Your hosting is already backed up automatically, twice a day, with backups kept for 30 days – see how to restore a backup of your website or email. A WP-CLI export is handy for an instant copy just before a change.

Export (back up) your database

wp db export ~/wp-backup-$(date +%F).sql

This saves a copy of your database in your home folder, with today’s date in the file name, for example wp-backup-2026-10-01.sql.

Save database backups in your home folder, not in public_html. Files in public_html can be downloaded by anyone who guesses the address, and your database contains private information such as user details. The ~/ in the command above saves it safely in your home folder.

Import (restore) a database

wp db import ~/wp-backup-2026-10-01.sql

Replace the file name with the one you want to restore.

Importing replaces your whole database. Anything changed since the backup was taken, such as new orders, comments or posts, will be lost. If in doubt, export your current database first so you can go back.

Other useful commands

CommandWhat it does
wp db size --human-readableShows how big your database is
wp db checkChecks your database tables for errors
wp db optimizeTidies up your database tables

Tidy up old backups

Database copies use space in your hosting plan. List them, and delete ones you no longer need:

ls -lh ~/*.sql
rm ~/wp-backup-2026-10-01.sql

You can also download a copy to your computer using FTP or the File Manager.

Need a hand? Please contact our support team. We look after your hosting and WP-CLI; problems inside WordPress plugins and themes are covered in do you support WordPress plugins and themes.

Updated on October 1, 2026
Was this article helpful?

Related Articles

Need Support?
Can't find the answer you're looking for? Don't worry we're here to help!
GET SOME HELP!