Ir al contenido

WP-CLI reference

Esta página aún no está disponible en tu idioma.

Migrator provides a complete set of WP-CLI commands. The command line runs directly in the terminal without browser execution timeouts or web server memory restrictions, making it the preferred tool for large WooCommerce stores and scripted automation.

Create a .migrator archive of the database and wp-content. The default excludes (cache folders, other backup plugins’ folders, node_modules, .git, log files over 10 MB) apply here too.

Terminal window
# Full site backup (a dated file in the backups folder)
wp migrator export
# Write the archive to a path of your choice
wp migrator export --output=/backups/mysite.migrator
# Leave parts out: database, media, themes, inactive-themes, plugins,
# inactive-plugins, muplugins, cache, spam-comments, post-revisions,
# transients, sessions, action-scheduler
wp migrator export --exclude=media,spam-comments,post-revisions
# Leave out exact tables, wp-content paths and file name patterns
wp migrator export --exclude-tables=wp_actionscheduler_logs --exclude-files=uploads/2019 --exclude-pattern="*.log,*.zip"
# Skip files larger than 50 MB
wp migrator export --max-file-size=50
# Gzip the finished archive (import detects it)
wp migrator export --compress

Import a .migrator archive into the current site. The source site’s URLs and paths are rewritten to this site’s. On a single site, a different table prefix is moved to this site’s prefix; a multisite restore still needs matching prefixes.

Terminal window
# Full restore with automatic URL rewriting
wp migrator import /path/to/backup.migrator
# Selective restore: plugins and themes only (useful under DISALLOW_FILE_MODS)
wp migrator import /path/to/backup.migrator --only=plugins,themes
# Parts you can pick: database, plugins, themes, uploads, other
wp migrator import /path/to/backup.migrator --only=database
# Database only, no wp-content files, no confirmation prompt
wp migrator import /path/to/backup.migrator --skip-files --yes
# Safe mode: every plugin except Migrator stays off afterwards, wp-admin offers to switch them back on
wp migrator import /path/to/backup.migrator --safe-mode
# Set a new password for an administrator (login or email) after the restore
MIGRATOR_ADMIN_PASSWORD='a-long-password' wp migrator import /path/to/backup.migrator --admin-user=admin

Without MIGRATOR_ADMIN_PASSWORD, --admin-user asks for the password at a prompt.

Serialization-safe search and replace: wp migrator replace

Section titled “Serialization-safe search and replace: wp migrator replace”

Safely rewrite domain names, URLs, or filesystem paths across your database. Migrator inspects PHP serialized objects and updates internal string length counts, preventing data corruption.

Terminal window
# Preview what would be updated across the database
wp migrator replace https://old-domain.com https://new-domain.com --dry-run
# Execute live replacement
wp migrator replace https://old-domain.com https://new-domain.com
# Replace filesystem absolute paths
wp migrator replace /var/www/vhosts/old/ /home/forge/new/

Direct server sync: wp migrator pull and wp migrator push

Section titled “Direct server sync: wp migrator pull and wp migrator push”

Migrator can stream a site between two active servers over HTTP without manual file transfers.

On the destination server, run:

Terminal window
wp migrator pull https://source-store.com
  1. On the first run, the command prints an authentication key.
  2. In the source site wp-admin, navigate to Migrator > Pull and Push and paste the key.
  3. Re-run wp migrator pull https://source-store.com.
  4. The database streams in chunks with automatic URL rewriting, followed by modified wp-content files. If interrupted, running the command again resumes where it stopped.

To sync local or staging file modifications back to the remote server:

Terminal window
wp migrator push https://target-store.com

You can trigger automated command-line backups using your operating system crontab:

# Run a compressed full backup every day at 02:00
0 2 * * * /usr/local/bin/wp migrator export --compress --path=/var/www/html > /dev/null 2>&1