How-to · WordPress

Back up a WordPress site (files and database)

At the end you will have a complete copy of the site on your computer: every file in the WordPress folder including wp-config.php, plus an SQL export of the database, checked and stored in more than one place.

Updated 8 steps5 official sources
Before you start

What you need before step 1

Applies to: Self-hosted WordPress (WordPress.org software) on any host with SFTP or a file manager, and phpMyAdmin or SSH

Admin roles you need

  • SFTP/FTP login or hosting control panel access to the site's files
  • Database access: phpMyAdmin through the control panel, or SSH with WP-CLI or mysqldump

Licences

None needed.

Install instructions

WP-CLIOnly if you will export the database over SSH; see the WP-CLI how-tohttps://make.wordpress.org/cli/handbook/guides/installing/Our step-by-step →Install steps

Also have ready

  • An SFTP or FTP client (WordPress's backup page mentions FTP clients and WinSCP), or your host's file manager
  • Enough free space on your computer for the whole site
  • The database name from wp-config.php (the DB_NAME line)
  • A second storage location for the copy (cloud storage, external disk)
SiteGround web hosting
Step by step

8 steps

  1. 1

    Connect to the site files

    Where: Your SFTP client on your PC (new site or new connection dialog)

    Set Protocol to SFTP, enter your host (for example contoso.com), port 22 and your SFTP username and password from your hosting account, then select Connect. Browse to the WordPress folder: the one containing wp-config.php, wp-content and wp-admin (often public_html).

    You should see: The remote pane lists wp-admin, wp-content, wp-includes, wp-config.php and .htaccess.
  2. 2

    Download every file

    Where: Your SFTP client: remote (server) pane

    Create an empty local folder such as contoso-backup-files in the left pane. Select everything in the WordPress folder, including wp-config.php and .htaccess (turn on the client's option to show hidden files so dot-files appear), right-click and select Download. If you have no SFTP access, use your host's file manager to compress the WordPress folder into a zip and download that instead.

    You should see: The transfer queue empties with no failed transfers, and the local folder contains wp-content (themes, plugins, uploads) and wp-config.php.
  3. 3

    Option A: export the database with WP-CLI

    Where: SSH session to the web server, in the WordPress folder

    Run wp db export. With no filename it names the file {dbname}-{Y-m-d}-{random-hash}.sql; giving a name makes it easier to find. Then download the .sql file with SFTP.

    cd /var/www/contoso.com/public_html
    wp db export contoso-backup.sql
    You should see: Success: Exported to 'contoso-backup.sql'.
  4. 4

    Option B: export the database with mysqldump

    Where: SSH session to the web server

    Use the database host, user and name from wp-config.php. Enter the database password when prompted. The second form compresses the file with gzip.

    mysqldump --add-drop-table -h localhost -u contoso_user -p contoso_wp > contoso-backup.sql
    mysqldump --add-drop-table -h localhost -u contoso_user -p contoso_wp | gzip > contoso-backup.sql.gz
    You should see: The command returns to the prompt and the .sql (or .sql.gz) file has a non-zero size.
  5. 5

    Option C: export the database with phpMyAdmin

    Where: Hosting control panel (for example cPanel > Databases > phpMyAdmin)

    Select your WordPress database in the left pane. Select the Export tab. Choose Custom, make sure the format is SQL, tick Add DROP TABLE / VIEW / PROCEDURE / FUNCTION / EVENT / TRIGGER statement, choose gzipped compression if you want a smaller file, then select Go. (Quick export with SQL format also works.) WordPress notes phpMyAdmin cannot handle large databases; use Option A or B for those.

    You should see: Your browser downloads a .sql or .sql.gz file named after the database.
  6. 6

    Keep wp-config.php safe and separate

    Where: Your PC

    wp-config.php holds the database name, user and password and the security keys. You downloaded it with the files; keep a second copy with the database export, and store the backup somewhere private because of the credentials it contains.

    You should see: You have wp-config.php in both the files backup and alongside the SQL export.
  7. 7

    Store copies in more than one place

    Where: Your PC, cloud storage, external disk

    Zip the files folder and the SQL export together and name the archive with the date. WordPress recommends keeping at least three backups in different locations, for example your host, cloud storage and your computer.

    You should see: The dated archive exists in at least two places besides the web server.
  8. 8

    Test the backup

    Where: Your PC, then a test or local WordPress environment

    Open the archive and confirm wp-content/uploads contains your media and the SQL file opens in a text editor and contains CREATE TABLE lines for your tables (prefix wp_ or the $table_prefix in wp-config.php). Ideally restore it to a staging or local site: copy the files back, import the SQL, update wp-config.php if the database details differ, and check the site loads.

    You should see: The test site loads with your pages, media and settings.
From experience

Expert tips

Take a consistent database dump of a live site

wp db export runs mysqldump and passes extra arguments to it, so on an InnoDB database add --single-transaction (wp db export backup.sql --single-transaction) to get a consistent snapshot without locking a busy shop or membership site.

Never leave the backup in the web root

A .sql file or zip left in public_html can be downloaded by anyone who guesses the name, and it contains every user record and password hash. Write it outside the web root (for example wp db export ~/backups/site.sql) or move it off the server straight away.

Keep several copies in different places

WordPress recommends keeping at least three to five recent backups in different places and on different media, such as the host, cloud storage and a local computer. A backup that exists only on the same server dies with that server or hosting account.

Script it with predictable file names

Without a file name, wp db export writes {dbname}-{Y-m-d}-{random-hash}.sql. Add --porcelain to print only the file name for scripts, or use wp db export - to stream to standard output and pipe it to gzip.

Back up immediately before every change

WordPress says to back up the database regularly and always before an upgrade. Treat a migration, a search-replace or a plugin update the same way: take a fresh export minutes before, so the restore point matches the moment you started.

Check it worked

How to confirm it worked

  • The local files folder size is close to the size your host reports for the site, and includes wp-content/uploads, wp-content/themes and wp-content/plugins.

  • The SQL file contains CREATE TABLE statements for every table in the database (compare with the table list in phpMyAdmin, or wp db tables).

  • A restore to a test site loads correctly.

Undo

How to reverse it

Rollback:

Taking a backup does not change the live site, so there is nothing to undo. Delete any .sql export left in the web folder on the server once it is downloaded, because it should not be publicly reachable.

Troubleshooting

Errors you might see

phpMyAdmin export times out or the file is incomplete

Cause: WordPress notes phpMyAdmin cannot handle large databases.

Fix: Export with wp db export or mysqldump over SSH instead.

.htaccess or other dot-files missing from the download

Cause: The SFTP client hides files starting with a dot.

Fix: Turn on the option to show hidden files in your SFTP client, then download again.

cPanel full backup cannot be restored through cPanel

Cause: WordPress notes cPanel full backups are strictly for archival purposes and cannot be restored via cPanel.

Fix: Use a database export plus a files download as described here.

mysqldump: Got error: 1045: Access denied for user

Cause: Wrong database user, password or host.

Fix: Copy DB_USER, DB_PASSWORD and DB_HOST exactly from wp-config.php.

FAQ

Questions

How often should I back up WordPress?

WordPress suggests weekly for small sites with few posts, daily for busy sites, and always before an upgrade.

Does a database export include my images?

No. Uploads, themes and plugins are files and must be backed up separately.

In what order do I restore?

Restore the files first, then import the database, then update wp-config.php if the database credentials changed.

Can I use a backup plugin instead?

Yes. Most hosts also provide backup tools. A manual backup is still a useful check that the process works.

Sources

Official sources

Vendors change menus and requirements. Confirm on the source before you rely on a detail. Last checked 4 Nov 2026.