WordPress pre-migration check (WP-CLI)
Run one read-only command on the old host and get a text report of the WordPress and PHP versions, active plugins and theme, site URLs, database size, uploads folder size and scheduled cron events, so you can match the new host and check nothing is missing after the move.
What you need
Modules and tools
Admin roles
- SSH access to the web server as the user that owns the WordPress files (not root)
Runs on
- Bash on the Linux web server that hosts the site (or any machine with WP-CLI and access to the site files and database)
Options you can set
| Parameter | What it does |
|---|---|
-p | Optional. Path to the WordPress folder (the one with wp-config.php). Default: the current folder. |
-u | Optional. Path to the uploads folder, if it is not wp-content/uploads under the WordPress folder. |
-o | Optional. Report file to write. Default: wp-precheck_yyyyMMdd-HHmm.txt in the current folder. |
-s | Optional flag. Run WP-CLI with --skip-plugins and --skip-themes, for sites where a plugin error stops WP-CLI from loading. |
Step by step
- 1
Step 1
Connect to the web server over SSH and check WP-CLI works:
wp --info. If not, follow install WP-CLI. - 2
Step 2
Save the script as
wp-pre-migration-check.shin your home folder and runchmod +x wp-pre-migration-check.sh. - 3
Step 3
Run
./wp-pre-migration-check.sh -p /var/www/contoso.com/public_html. - 4
Step 4
Download the report it names (for example with scp or your host's file manager) and keep it with your migration notes.
- 5
Step 5
After the migration, run the same script on the new host and compare the two reports.
What you get: A text report with sections for WP-CLI and PHP environment, WordPress version, core update check, siteurl and home, active plugins, must-use plugins and drop-ins, active theme, database size (total and per table), uploads folder size and file count, and scheduled cron events. Any command that fails is marked FAILED in its section.
wp-pre-migration-check.sh
#!/usr/bin/env bash
# ----------------------------------------------------------------------------
# wp-pre-migration-check.sh
#
# Purpose: read-only pre-migration report for a WordPress site using WP-CLI:
# WordPress and PHP versions, siteurl and home, active plugins and theme,
# database size, uploads folder size, and scheduled cron events.
# It only runs list, get and size commands. It changes nothing.
#
# Provided by cloud-migrations.au as is; test before use.
#
# Requirements: bash, WP-CLI (wp) on the PATH, du and find, and run it as the user
# that owns the WordPress files.
#
# Usage:
# ./wp-pre-migration-check.sh -p /var/www/contoso.com/public_html
# ./wp-pre-migration-check.sh -p /var/www/contoso.com/public_html -o ~/contoso-before.txt -s
#
# Note: "wp cli info" shows the PHP binary WP-CLI uses on the command line. WP-CLI's
# handbook notes the command-line php.ini is typically different from the web
# server's, so confirm the web PHP version in your hosting control panel too.
# ----------------------------------------------------------------------------
set -u
WP_PATH="$(pwd)"
UPLOADS=""
OUTFILE="$(pwd)/wp-precheck_$(date +%Y%m%d-%H%M).txt"
SKIP=0
usage() {
echo "Usage: $0 [-p wordpress-path] [-u uploads-path] [-o report-file] [-s]"
exit 1
}
while getopts "p:u:o:sh" opt; do
case "$opt" in
p) WP_PATH="$OPTARG" ;;
u) UPLOADS="$OPTARG" ;;
o) OUTFILE="$OPTARG" ;;
s) SKIP=1 ;;
*) usage ;;
esac
done
[ -z "$UPLOADS" ] && UPLOADS="${WP_PATH%/}/wp-content/uploads"
if ! command -v wp >/dev/null 2>&1; then
echo "ERROR: WP-CLI (wp) is not on the PATH. Install it first." >&2
exit 2
fi
WP=(wp "--path=${WP_PATH}")
[ "$SKIP" -eq 1 ] && WP+=(--skip-plugins --skip-themes)
if ! "${WP[@]}" core is-installed >/dev/null 2>&1; then
echo "ERROR: no installed WordPress found at ${WP_PATH} (wp core is-installed failed)." >&2
exit 2
fi
: > "$OUTFILE" || { echo "ERROR: cannot write ${OUTFILE}" >&2; exit 3; }
section() {
# section "Heading" command args...
local heading="$1"; shift
echo " ${heading}"
{
echo ""
echo "=== ${heading} ==="
if ! "$@" 2>&1; then
echo "FAILED: $*"
fi
} >> "$OUTFILE"
}
{
echo "WordPress pre-migration check"
echo "Site path: ${WP_PATH}"
echo "Taken: $(date -u '+%Y-%m-%d %H:%M:%S') UTC on $(hostname)"
} >> "$OUTFILE"
echo "Checking WordPress at ${WP_PATH}..."
section "WP-CLI and PHP environment (command line)" wp cli info
section "WordPress version" "${WP[@]}" core version --extra
section "WordPress core updates" "${WP[@]}" core check-update
section "siteurl" "${WP[@]}" option get siteurl
section "home" "${WP[@]}" option get home
section "Active plugins" "${WP[@]}" plugin list --status=active --fields=name,status,version,update
section "Must-use plugins" "${WP[@]}" plugin list --status=must-use
section "Drop-ins" "${WP[@]}" plugin list --status=dropin
section "Active theme" "${WP[@]}" theme list --status=active
section "Database size" "${WP[@]}" db size
section "Database tables by size" "${WP[@]}" db size --tables --human-readable --orderby=size --order=desc
section "Scheduled cron events" "${WP[@]}" cron event list
# Uploads folder size and file count (plain shell, read-only)
echo " Uploads folder"
{
echo ""
echo "=== Uploads folder (${UPLOADS}) ==="
if [ -d "$UPLOADS" ]; then
du -sh "$UPLOADS" 2>&1
echo "Files: $(find "$UPLOADS" -type f 2>/dev/null | wc -l | tr -d ' ')"
else
echo "FAILED: folder not found. Use -u to give the uploads path."
fi
} >> "$OUTFILE"
echo ""
echo "Report saved to: $(cd "$(dirname "$OUTFILE")" && pwd)/$(basename "$OUTFILE")"Commands documented here
Every command in the script is documented on these vendor pages. Test in a non-production tenant or environment first.