How to back up a WordPress site properly (and prove it works)
Back up the database and wp-content daily, keep copies off-site for 30 days, and test a restore. The setup, a WP-CLI script and the mistakes to avoid.
By Sohail Hussain21 November 20265 min read
A proper WordPress backup has four parts. It copies the database and the wp-content folder, plus wp-config.php and .htaccess. It runs automatically, on a schedule that matches how often the site changes. It is stored somewhere other than your hosting account. And it has been restored successfully at least once. Most sites have the first part. Few have the last, and a backup that has never been restored is a hope, not a plan.
This is the setup we run on WordPress sites under our website care and maintenance plans. You can set up the same thing yourself in an afternoon.
What does a WordPress backup need to include?
Two things, and you need both to restore a site:
- The database. Every post, page, setting, user, form entry and order. Without it you have a theme and no content.
- The files. The
wp-contentfolder holds your uploads (every image and document), themes and plugins.wp-config.phpholds the database connection and security keys..htaccessholds rewrite rules and any redirects added there.
WordPress core files (wp-admin and wp-includes) can always be downloaded fresh, so they are optional. Including them costs little and makes a restore simpler, so most tools do.
Exclude cache folders and old backup files stored inside wp-content. A plugin that saves its archives into wp-content and then backs up that folder produces archives that grow with every run.
How often should you back up, and for how long?
Match the schedule to how much work you could bear to lose:
| Site | Database | Files | Keep copies for |
|---|---|---|---|
| Brochure site, edited monthly | Daily | Weekly | 30 days |
| Site with a blog or form entries | Daily | Daily | 30 days |
| WooCommerce store or membership site | Hourly or real-time | Daily | 30 to 90 days |
The retention column matters more than it looks. Hacks and accidental deletions are often noticed weeks later, and a schedule that keeps only seven days may hold nothing but bad copies. The official WordPress backup guide recommends keeping several recent backups in different places for the same reason.
Take an extra backup before every update, migration or large content change.
Which backup method should you use?
| Method | Where copies live | Restore effort | Cost (as of October 2026) | Weak point |
|---|---|---|---|---|
| Host backups | Usually the host's own storage | One click, if the host is healthy | Often included | Lost if the account is lost, suspended or compromised |
| Backup plugin (UpdraftPlus, WPvivid and similar) | Cloud storage you connect | Moderate; usually needs a working WordPress to restore from | Free, or roughly $50 to $100 a year for premium versions | Runs inside WordPress, so a broken site can break the backup |
| Managed backup service (BlogVault, Jetpack VaultPress Backup and similar) | The service's servers | Easy; can restore from outside WordPress | Roughly $50 to $200 a year per site | Another subscription and vendor |
| WP-CLI script and cron | Wherever you send it | Manual; needs SSH | Storage only | Needs someone comfortable on a server |
The setup we recommend uses two. Host backups give quick rollbacks. A second, independent copy goes to storage the host cannot touch, such as an Amazon S3, Backblaze B2 or Google Drive account in the company's own name. Give that storage its own login, so an attacker who gets into the hosting account cannot delete the backups as well.
How do you set up backups with WP-CLI?
If you have SSH access, a short script does the job without a plugin. It uses wp db export, which writes the database to standard output when given -, as the WP-CLI documentation describes:
#!/bin/sh
set -e
SITE=/var/www/example.com
DEST=$HOME/backups
STAMP=$(date +%F)
mkdir -p "$DEST"
cd "$SITE"
wp db export - | gzip > "$DEST/db-$STAMP.sql.gz"
tar -czf "$DEST/files-$STAMP.tar.gz" --exclude=wp-content/cache wp-content wp-config.php .htaccess
rclone copy "$DEST" offsite:example-com-backups
find "$DEST" -type f -mtime +30 -delete
The script exports the database, archives the files without the cache folder, copies both off-site with rclone (set up beforehand with a remote named offsite), and deletes local copies older than 30 days. Adjust the paths if wp-config.php sits one level above the WordPress folder, which some hosts do. Schedule the script with cron, for example every night at 02:30 server time:
30 2 * * * /home/deploy/bin/backup-wp.sh >> /home/deploy/backup.log 2>&1
Our cron expression generator builds and explains other schedules. The local copies are a convenience; the off-site copy is the backup that counts.
How do you test that a backup actually restores?
Restore it somewhere that is not the live site: a staging subdomain or a local copy with its own database. Keep the staging site's own wp-config.php, so the import goes into the staging database and never the live one. Then, from the staging site's folder:
tar -xzf files-2026-10-30.tar.gz wp-content
gunzip < db-2026-10-30.sql.gz | wp db import -
wp search-replace 'https://example.com' 'https://staging.example.com' --skip-columns=guid
The first line extracts only wp-content from the archive. The last line points the restored content at the staging address. The staging wp-config.php must use the same table prefix as the live site, or WordPress will not find the imported tables.
Then check: the homepage loads, images appear, you can log in, a form submits, and the most recent content is there. Note how long the whole restore took. That is your real recovery time, and the person who will do it under pressure should have done it once in calm conditions.
Test a restore when you first set backups up, and every quarter after that.
What mistakes make backups useless?
- Copies stored only on the same server. If the server fails or the account is compromised, they go with it.
- Database only. A restore without uploads is a site with no images.
- Failing silently. Storage fills up, an access token expires, and the plugin quietly stops uploading. Turn on failure emails and look at the backup log every month.
- Too short a history. Seven days of copies of a site that was infected three weeks ago.
- Nobody knows how to restore. Write down where backups live, who has access, and the steps. Keep that note somewhere other than the website.
- Restoring the hack. After a compromise, restore from before the infection, then close the hole it came through. WordPress keeps getting hacked covers that process.
For backups across all platforms, not only WordPress, see website backups: what good looks like. For where backups fit in the rest of a WordPress setup, see WordPress for business websites.
Was this guide useful?