Website files and the database: the two halves of a backup
Copying your site's files doesn't copy your content. On a typical WordPress site, the database is stored in a separate system outside the site's folder, so a folder download leaves it behind.1
What each half does
Think of the files as the building and the database as the contents of the filing cabinets inside it.
The files hold the software, the look of the site, and anything you've uploaded. The database holds the posts, pages, comments and settings.2 Neither half works alone.
The database part has a trade term worth explaining. A database is an organised store of records that the site reads each time a page loads. MySQL and MariaDB are two common database systems.1
Why the folder copy misses it
The WordPress handbook is plain on this. You usually can't back up the database by downloading the WordPress directory, because the database lives outside it.3
The reverse is also true. The database steps don't back up themes, plugins, uploads or wp-config.php.2 So two jobs, two copies.
| If you only have... | You're missing |
|---|---|
| The files | Posts, pages, comments and settings2 |
| The database | Themes, plugins, uploads and wp-config.php2 |
How the database becomes a file
You can't download a database like a folder. You export it, which creates a single file, for example a .sql, .gz or .bz2 file.3
That export is an ordinary file. You can keep it next to your file backup so the two stay together as one set. But restoring still means importing it back into MySQL or MariaDB.2
Many hosts give you a tool for this, such as phpMyAdmin, which has an Export tab.2 The steps differ by host and version, so follow your host's own instructions for your account.
Keeping the pair matched
The handbook suggests treating the files and the database as one "backup set", created around the same time.3 A database from last month paired with files from today can disagree about what's installed.
Its typical order is:
- Back up the database first, then the files.
- When restoring, put the files back first, then import the database.3
The one file that links them
The wp-config.php file holds your connection details.1 That's how the files find the database. If a site is moved and the database login changes, the handbook says to update wp-config.php to match.3
So a missing or wrong wp-config.php can leave perfectly good files unable to reach perfectly good content.
If you don't use WordPress
Other systems, from shop software to custom code, often follow the same split. Code and uploads live in files, and records live in a database. Look in your platform's documentation for where its database is kept and how it exports one. This site doesn't cover each platform, so check yours.
Once you hold both halves, separate places for each copy explains where to put them.
Sources used
- Backing Up Your WordPress Files, WordPress Developer Resources
- Backing Up Your Database – Advanced Administration Handbook, WordPress Developer Resources
- Backups – Advanced Administration Handbook, WordPress Developer Resources