n5s / wp-cli-move
Sync your WordPress content (database and uploads) between stages using the power of WP-CLI aliases.
Fund package maintenance!
Requires
- php: ^8.1
Requires (Dev)
- ergebnis/composer-normalize: ^2.45
- php-stubs/wordpress-stubs: ^6.7
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.1
- rector/rector: ^2.0
- slevomat/coding-standard: ^8.14
- szepeviktor/phpstan-wordpress: ^2.0
- wp-cli/config-command: ^2.3 || ^3.0
- wp-cli/core-command: ^2.1 || ^3.0
- wp-cli/db-command: ^2.0 || ^3.0
- wp-cli/eval-command: ^2.2 || ^3.0
- wp-cli/search-replace-command: ^2.1 || ^3.0
- wp-cli/wp-cli-tests: ^4.3 || ^5.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-04 11:26:50 UTC
README
Sync your WordPress content (database and uploads) between stages using the power of WP-CLI aliases.
Install
Using composer:
composer require n5s/wp-cli-move --dev
Using wp package install:
wp package install nlemoine/wp-cli-move:^0.1.0
Requirements
The requirements must be met on both stages.
- SSH access
- WP-CLI 2.12 or 3.x
- mysql/mysqldump
- rsync
- gzip (optional, can be disabled with the
--disable-compressflag)
Before running commands, make sure you have WP-CLI aliases set up. This can be done either with the wp cli alias command or by editing your wp-cli.yml file.
Once you're done, quickly check that remote WP-CLI commands work as expected:
wp @your-alias option get home
# It should print your alias home URL
https://example.org
For more information about alias configuration, refer to the following WP-CLI documentation:
- https://make.wordpress.org/cli/handbook/guides/running-commands-remotely/#aliases
- https://make.wordpress.org/cli/handbook/references/config/
SSH settings
wp-cli-move runs its own ssh and rsync commands next to the wp @alias ones (to stream database dumps and sync uploads). They use the same alias SSH settings as WP-CLI:
ssh: user, host and portkey,proxyjumpandssh_config, set on the alias or, with WP-CLI 3, at the root of the configuration for all aliasesssh-args(WP-CLI 3), written as a list, one argument per item. Like WP-CLI,ssh-argswritten as a single string are ignored.
key: ~/.ssh/id_ed25519 "@production": ssh: deploy@example.org/var/www/example.org ssh-args: - -oControlMaster=auto - -oControlPath=~/.ssh/cm-%r@%h:%p
Global parameters given to wp move (e.g. --ssh-args, --debug) are passed on to the wp @alias commands, except the ones that point to the local install (--path, --url, --user, --ssh, --http, --require, --exec, --prompt).
Other schemes (docker, docker-compose, vagrant...) are left to WP-CLI for remote commands, uploads can only be synced over SSH.
Usage
Depending on the sync direction, use either the pull or push commands.
wp move pull/push [<alias>] [--db] [--uploads] [--disable-compress] [--dry-run]
If you omit the --db or --uploads flags, both data types will be synced by default.
Note that the <alias> argument is optional. Configured aliases will be shown in a menu to choose from if left empty.
Caution
Just like any tool that manipulates your data, it's always a good idea to make a backup before running commands.
Especially when syncing uploads, which uses the rsync command with the --delete flag under the hood and can wipe all your media files if used incorrectly.
Be sure to know what you're doing.
Options
Both pull and push commands use the same options.
[<alias>]: The alias you want to sync with.--db: Sync only the database.--uploads: Sync only the uploads.--disable-compress: Disable database dump compression.--dry-run: Print the command sequence without making any changes.
Note
Each time you sync your database from one stage to another, wp-cli-move will locally backup the database of the synced stage (a local database dump when pulling, a remote database dump when pushing).
Syncing to a fresh install
The destination does not need a working WordPress install, only its files and a wp-config.php with valid database credentials. If its database does not exist yet, it is created (wp db create) instead of backed up, and uploads are synced once the database is in place.
Its home URL cannot be read from an empty database though, set it in the configuration:
# Pulling into a fresh local install: wp-cli.yml (or --url) url: https://example.test # Pushing to a fresh remote install: the alias "@staging": ssh: deploy@example.org/var/www/staging url: https://staging.example.org
A WP_HOME constant works too, even when wp-config.php reads it from the environment (e.g. a .env file).
URL replacement
After a database sync, the source home URL is replaced with the destination one (wp search-replace) in every table sharing the install prefix (--all-tables-with-prefix), not only the WordPress core tables. Plugin tables that are not registered on $wpdb (e.g. Yoast indexables) are covered too.
If several installs share the same database, make sure one prefix does not start with another (e.g. wp_ and wp_staging_): tables of the other install would match too.
Multisite
Multisite installations are supported. In addition to the home URL replacement, wp-cli-move will:
- bootstrap WordPress with the source URL (
--url=...): right after an import, the database does not match the configuredDOMAIN_CURRENT_SITEanymore, WordPress could not load otherwise - run every replacement on the tables of all the sites of the network, as they share the base prefix: a link to a site from another site's content is replaced too
- on subdomain networks, run a dedicated replacement pair for each site (
https://en.example.org→https://en.example.test) - replace the bare domain (e.g.
example.org→example.test) in thewp_siteandwp_blogstables only: email addresses or domain mentions in content are left untouched
Network types:
- Subdirectory networks are fully covered.
- Subdomain networks are covered as long as domains are renamed consistently between stages (
en.example.orgon production is expected to been.example.testlocally). - Domain mapped sites are skipped with a warning: there is no way to guess their destination domain. Sites with custom mapped domains keep them after a sync.
Examples
Pulling content
Pull your production content to your local environment:
wp move pull @production
Tip
Using @ as declared in wp-cli.yml is optional. For example, production and @production will resolve the same alias.
Pushing content
Push your local content to your staging environment:
wp move push staging
Credits
This WP-CLI package aims to replace the (still working but unmaintained) awesome Wordmove Ruby gem 💎. It has been a time and life saver for many years. I'll be forever grateful to @alessandro-fazzi for creating it! 🙌
Although Wordmove is a great and handy tool for your daily WordPress work, some reasons led me to come with a simpler, more WordPress flavoured alternative:
- It has become harder to easily install the gem over the years as the required Ruby version has been deprecated, especially for non-Ruby developers (at least for me).
- Most importantly, an idea I submitted years ago has never been implemented. This feature would remove a lot of tedious configuration setup (database credentials, etc.).
- It's written in Ruby 😄