|
1 | 1 | # wp-cli-move
|
| 2 | + |
2 | 3 | Sync your WordPress content (database and uploads) between stages using the power of WP-CLI aliases.
|
| 4 | + |
| 5 | +## Install |
| 6 | + |
| 7 | +Using composer: |
| 8 | + |
| 9 | +```sh |
| 10 | +composer require n5s/wp-cli-move --dev |
| 11 | +``` |
| 12 | + |
| 13 | +Using `wp package install`: |
| 14 | + |
| 15 | +```sh |
| 16 | +wp package install n5s/wp-cli-move |
| 17 | +``` |
| 18 | + |
| 19 | +## Requirements |
| 20 | + |
| 21 | +The requirements must be met on both stages. |
| 22 | + |
| 23 | +- SSH access |
| 24 | +- WP-CLI |
| 25 | +- mysql/mysqldump |
| 26 | +- rsync |
| 27 | +- gzip (optional, can be disabled with the `--disable-compress` flag) |
| 28 | + |
| 29 | +Before running commands, make sure you have WP-CLI aliases set up. This can be done either with the [`wp cli alias`](https://developer.wordpress.org/cli/commands/cli/alias/) command or by editing your `wp-cli.yml` file. |
| 30 | + |
| 31 | +Once you're done, quickly check that remote WP-CLI commands work as expected: |
| 32 | + |
| 33 | +```sh |
| 34 | +wp @your-alias option get home |
| 35 | + |
| 36 | +# It should print your alias home URL |
| 37 | +https://example.org |
| 38 | +``` |
| 39 | + |
| 40 | +For more information about alias configuration, refer to the following WP-CLI documentation: |
| 41 | + |
| 42 | +- https://make.wordpress.org/cli/handbook/guides/running-commands-remotely/#aliases |
| 43 | +- https://make.wordpress.org/cli/handbook/references/config/ |
| 44 | + |
| 45 | +## Usage |
| 46 | + |
| 47 | +Depending on the sync direction, use either the `pull` or `push` commands. |
| 48 | + |
| 49 | +```sh |
| 50 | +wp move pull/push [<alias>] [--db] [--uploads] [--disable-compress] [--dry-run] |
| 51 | +``` |
| 52 | + |
| 53 | +If you omit the `--db` or `--uploads` flags, both data types will be synced by default. |
| 54 | + |
| 55 | +Note that the `<alias>` argument is optional. Configured aliases will be shown in a menu to choose from if left empty. |
| 56 | + |
| 57 | +> [!CAUTION] |
| 58 | +> Just like any tool that manipulates your data, it's **always a good idea to make a backup before running commands**. |
| 59 | +> |
| 60 | +> 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. |
| 61 | +> |
| 62 | +> **Be sure to know what you're doing.** |
| 63 | +
|
| 64 | +### Options |
| 65 | + |
| 66 | +Both `pull` and `push` commands use the same options. |
| 67 | + |
| 68 | +- `[<alias>]`: The alias you want to sync with. |
| 69 | +- `--db`: Sync only the database. |
| 70 | +- `--uploads`: Sync only the uploads. |
| 71 | +- `--disable-compress`: Disable database dump compression. |
| 72 | +- `--dry-run`: Print the command sequence without making any changes. |
| 73 | + |
| 74 | +> [!NOTE] |
| 75 | +> 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). |
| 76 | +
|
| 77 | +### Examples |
| 78 | + |
| 79 | +### Pulling content |
| 80 | + |
| 81 | +Pull your production content to your local environment: |
| 82 | + |
| 83 | +```sh |
| 84 | +wp move pull @production |
| 85 | +``` |
| 86 | + |
| 87 | +> [!TIP] |
| 88 | +> Using `@` as declared in `wp-cli.yml` is optional. For example, `production` and `@production` will resolve the same alias. |
| 89 | +
|
| 90 | +### Pushing content |
| 91 | + |
| 92 | +Push your local content to your staging environment: |
| 93 | + |
| 94 | +```sh |
| 95 | +wp move push staging |
| 96 | +``` |
| 97 | + |
| 98 | +## Credits |
| 99 | + |
| 100 | +This WP-CLI package aims to replace the (still working but unmaintained) awesome [Wordmove](https://github.com/welaika/wordmove) Ruby gem 💎. It has been a time and life saver for many years. I'll be forever grateful to [@alessandro-fazzi](https://github.com/alessandro-fazzi) for creating it! 🙌 |
| 101 | + |
| 102 | +Although [Wordmove](https://github.com/welaika/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: |
| 103 | + |
| 104 | +- 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). |
| 105 | +- Most importantly, [an idea I submitted years ago](https://github.com/welaika/wordmove/issues/601#issue-612726521) has never been implemented. This feature would remove a lot of tedious configuration setup (database credentials, etc.). |
| 106 | +- It's written in Ruby 😄 |
0 commit comments