How to update WordPress safely with WP-CLI: backup, update, verify, roll back
A repeatable WordPress update routine with WP-CLI: check pending updates, export the database and archive files, update core, plugins, themes and translations in order, verify checksums, and restore if something breaks.
8 min read

In this article
Updates are the single most effective thing you can do for a WordPress site's security, and also the most common cause of "the site broke this morning". The fix is not to avoid updates but to make them boring: back up, update in a fixed order, verify, and know exactly how to roll back.
This guide gives you that routine using WP-CLI, the official command-line tool for WordPress. Every command below is from the WP-CLI command reference, and the backup and restore order follows the official Advanced Administration Handbook. The current WordPress release is 7.1.3, a security release published on 6 October 2026 with seven security fixes, so there is a good reason to practise now.
You will need SSH access to the server (or a container with WordPress), and permission to run PHP on the command line. If your host does not offer SSH, the same order of steps applies through its dashboard and backup tools.
Step 0: Install WP-CLI
WP-CLI requires PHP 7.2.24 or later and has no other requirements beyond those of WordPress itself. The recommended install is the Phar archive:
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp --infoMany managed hosts already include wp; run wp --info to check. If the server has several PHP versions, the WP-CLI handbook explains how to use a custom PHP binary by putting it first in your PATH. The handbook also publishes a wp-cli.phar.asc signature you can check with gpg --verify before installing.
Step 1: See what will change
Before touching anything, record the current state. These commands are read-only:
cd /var/www/example.com/htdocs # your WordPress root
wp core version
wp core check-update
wp plugin list --update=available --fields=name,version,update_version
wp theme list --update=available --fields=name,version,update_version
# Baseline: are core files untouched before we start?
wp core verify-checksumsRead the changelogs for any plugin jumping a major version. A clean verify-checksums result now also gives you a baseline: if it fails later, you know the update caused it.
If a major WordPress release is waiting (for example from 7.0 to 7.1), read the release post and field guide first. WordPress 7.1 made the post editor always load in an iframe, which can affect older plugins that add editor scripts.
Step 2: Back up the database and the files
The handbook's backup page stresses that a WordPress backup has two parts, and that copying the WordPress folder does not back up the database. It recommends backing up the database first and then the files, and keeping both together as one set:
STAMP=$(date +%Y%m%d-%H%M)
BACKUP_DIR="$HOME/backups/example.com/$STAMP"
mkdir -p "$BACKUP_DIR"
# 1. Database first
wp db export "$BACKUP_DIR/db.sql" --add-drop-table
# 2. Then the files (core, wp-content, wp-config.php, .htaccess)
tar -czf "$BACKUP_DIR/files.tar.gz" -C /var/www/example.com htdocs
# 3. Prove the backup is usable
ls -lh "$BACKUP_DIR"
gzip -t "$BACKUP_DIR/files.tar.gz" && echo "archive OK"wp db export runs mysqldump with the credentials from wp-config.php and accepts any valid mysqldump flag, such as --add-drop-table above. If you omit a file name, it creates one named after the database and date.
Two rules from the handbook are worth repeating:
- Verify the backup is there and usable before updating. The manual upgrade instructions call this "essential".
- Keep copies off the server. The handbook suggests three to five recent backups in different places, such as the server, cloud storage and a local machine. Copy
$BACKUP_DIRelsewhere withrsyncor your storage tool of choice.

Step 3: Update in a fixed order
Update core first, then plugins, then themes, then translations. Running wp core update-db after a core update applies any database changes the new version needs, the same routine the browser-based updater runs after an upgrade.
# See what would change, without changing anything
wp plugin update --all --dry-run
# Core: update, then run any database upgrade routine
wp core update
wp core update-db
# Plugins and themes
wp plugin update --all
wp theme update --all
# Translations
wp language core update
wp language plugin update --all
wp language theme update --allWP-CLI puts the site into maintenance mode while it replaces plugin files and takes it out again afterwards. If a run is interrupted and you see "Another update is currently in progress", the reference advises deleting the core_updater.lock option with wp option delete core_updater.lock, but only after confirming no other update is actually running.
Being selective
You do not have to update everything at once. wp plugin update supports exclusions, minor-only and patch-only updates, and pinning to a version:
# Hold back a plugin you need to test separately
wp plugin update --all --exclude=woocommerce
# Only take minor/patch releases of plugins today
wp plugin update --all --minor
# Pin a plugin to a known version (also how you roll one back)
wp plugin update my-plugin --version=2.3.1The --version flag is also the quickest way to roll back a single plugin, provided the old version is still available from its source.
Step 4: Verify the result
Check integrity first, then behaviour:
wp core verify-checksums
wp plugin verify-checksums --all
wp db check
# Quick HTTP smoke test of key pages
for path in / /blog/ /contact/ /wp-login.php; do
printf '%s ' "$path"; curl -s -o /dev/null -w '%{http_code}\n' "https://example.com$path"
doneThen check by hand what matters to the business: log in, edit and preview a post, submit the contact form, place a test order if you run a shop, and look at the PHP error log. Open Tools → Site Health to see whether WordPress reports new critical issues.
| Check | Command or place | Pass condition |
|---|---|---|
| Core version | wp core version | Matches the latest release (7.1.3 on 7 Oct 2026) |
| Core files intact | wp core verify-checksums | "Success: WordPress installation verifies against checksums." |
| Plugin files intact | wp plugin verify-checksums --all | No errors for WordPress.org plugins |
| Database tables healthy | wp db check | All tables report OK |
| Key pages respond | curl loop above | 200 (or expected redirects) |
| Editor works | Open and save a post | No block errors, no console errors |
| Errors | PHP error log, Site Health | No new fatal errors or warnings |
Step 5: Roll back if something breaks
If the site is broken and a single plugin is the cause, deactivate it with wp plugin deactivate <name> or pin it to the previous version. If the problem is wider, restore the backup set. The handbook's restore order is files first, then the database:
# Put the site in maintenance mode while you restore
wp maintenance-mode activate
# Restore files, then the database (restore order from the handbook)
tar -xzf "$BACKUP_DIR/files.tar.gz" -C /var/www/example.com
wp db import "$BACKUP_DIR/db.sql"
wp maintenance-mode deactivatewp db import reads the SQL file using the credentials in wp-config.php. By default it also relaxes SQL modes that WordPress core disables, so older dumps with legacy values import cleanly. If database credentials changed during a migration, update wp-config.php before importing.
Practise this on a staging copy at least once. A backup you have never restored is an assumption, not a plan.

Step 6: Decide what to automate
WordPress has four kinds of automatic background updates: core, plugins, themes and translations. According to the upgrade documentation:
- Minor core updates (maintenance and security releases) and translations are enabled by default, and disabling them is "strongly discouraged".
- Since WordPress 5.6, new installations also auto-update to major releases, unless WordPress detects a version-control checkout. Existing sites keep their earlier behaviour until an administrator, constant or filter changes it.
WP_AUTO_UPDATE_COREinwp-config.phpacceptstrue,falseor'minor', and overrides the setting on the Updates screen.
A reasonable policy for a small business site is: minor core updates automatic, major core updates by hand after a backup, and automatic updates enabled for low-risk plugins only. WP-CLI can switch plugin auto-updates on:
# Turn on background auto-updates for selected plugins
wp plugin auto-updates enable akismet query-monitor
# Or for every plugin that does not have them yet
wp plugin auto-updates enable --all --disabled-onlyFor sites deployed from Git, keep updates in your repository instead and set DISALLOW_FILE_MODS so nobody updates production from wp-admin. Run the same update commands on a development copy, commit the result and deploy it.
A one-page update runbook
- Read release notes for core and any major plugin updates.
wp core check-update,wp plugin list --update=available.wp db export, archive files, verify, copy off-server.wp core updateandwp core update-db.wp plugin update --all(with--excludefor risky ones),wp theme update --all, language updates.wp core verify-checksums,wp plugin verify-checksums --all,wp db check.- Smoke-test key pages and editor; check error logs and Site Health.
- If broken: deactivate or pin the culprit, or restore files then database.
- Note what changed and when, for the next person.
Next steps
Turn the commands above into a script stored with your site's documentation, and run it on staging before production for major releases. Schedule it monthly at a minimum, and immediately when WordPress publishes a security release such as 7.1.3.
Frequently asked questions
Does backing up the WordPress folder include the database?
No. The database lives in MySQL or MariaDB, outside the WordPress folder. You need a database export (for example
wp db export) and a copy of the files to restore a site fully.In what order should I restore a WordPress backup?
The official backup documentation recommends restoring the files first and then importing the database. When backing up, do the reverse: database first, then files.
Why run wp core update-db after updating?
Some releases change the database.
wp core update-dbruns WordPress's database update routine, which the browser-based updater would otherwise prompt for. Use--dry-runto compare versions without making changes.How do I roll back one plugin with WP-CLI?
Run
wp plugin update <plugin> --version=<previous-version>. It installs that specific version, if it is still available from the plugin's source. Deactivating the plugin is the quicker emergency option.
Your next customer could start right here.
Introduce your tool, product or business to readers exploring technology.
Explore placements and request a private quote
Sources
- Upgrading WordPress — WordPress Advanced Administration Handbook
- Backups — WordPress Advanced Administration Handbook
- Installing WP-CLI — WP-CLI Handbook
- wp core update — WP-CLI Command Reference
- wp db export — WP-CLI Command Reference
- wp plugin update — WP-CLI Command Reference
- wp db import — WP-CLI Command Reference
- WordPress 7.1.3 Maintenance and Security Release — WordPress.org News, 2026-10-06
Written with substantial AI assistance. Facts checked against cited sources. Editorial policy.
Comments
No comments yet. Be the first to join the conversation.
Leave a comment
Every comment is read by a moderator before it appears. Your email address is never published; it is used only to contact you about this comment.
More from Cloudsoft Zone

Resource guideWordPress
WordPress security hardening checklist for 2026 (WordPress 7.1)
A practical WordPress 7.1 hardening checklist based on the official handbook: updates, two-step logins, wp-config.php constants, file permissions, database privileges, firewalls, WP-CLI checksum checks and tested backups.
By Cloudsoft Zone

Troubleshooting guideCodeIgniter
CodeIgniter 4 validation not working? 9 causes and fixes
Fix CodeIgniter 4 validation problems fast: wrong input source, lost errors after redirect, permit_empty, strict JSON rules, is_unique placeholders and more.
By Cloudsoft Zone

Interview preparationInterview questions
Docker interview questions and answers for Docker Engine 29
18 Docker interview questions from images and volumes to build cache, Compose, networking, signals and the containerd image store, with short model answers.
By Cloudsoft Zone
