wordmove

repository·master·Indexed 23 days ago

https://github.com/welaika/wordmove

A command-line tool for automating the mirroring of WordPress installations and databases between local development environments and remote servers. It provides a CLI to push and pull core files, uploads, themes, plugins, and databases using SSH or FTP. Key features include a diagnostic 'doctor' tool for environment checks, a hook system for executing custom shell commands during transfers, and integration with WP-CLI for SQL search-replace operations.

Tokens
3.9K
Snippets
6
Records
27
Agent score
83%

What's inside wordmove

  1. Important: Mirroring behavior and file exclusion

    master

    Wordmove's push and pull actions perform a mirror operation. This means:

    1. New/updated files are transferred.
    2. Files present on the destination that are NOT in the source will be deleted.

    Critical Action: If you have files or directories on your remote server that must be preserved (e.g., specific logs, user-uploaded content not in your local dev environment, or system files), you MUST add them to the exclude list in your movefile.yml to prevent them from being deleted during a sync.

  2. Configure multiple environments in movefile.yml

    master

    Wordmove supports multistage deployments (e.g., local, staging, production) by defining multiple environments in your movefile.yml.

    Any top-level key in the YAML file (other than global, local, or database) is treated as a remote environment. To target a specific environment, use the -e flag with your command.

    Example: Pushing to staging

    wordmove push -e staging -d
    wordmove push -e staging -d
  3. Simulate SSH deployments with --dry-run

    master
    When using the SSH deployer, you can simulate file transfers and commands without actually modifying the remote or local filesystems. For commands that use rsync (like directory transfers), Wordmove automatically appends the --dry-run flag to the rsync_options to ensure no real changes occur during a simulation.
  4. Load environment-specific variables from .env files

    master

    Wordmove can automatically load environment variables from .env files. It looks for files matching the pattern .env{.#{environment},} in the start_dir.

    For example, if your environment is set to production, Wordmove will look for .env.production or .env.

  5. Configure Wordmove using a Movefile

    master

    Wordmove uses a configuration file named Movefile (case-insensitive, e.g., movefile.yml, movefile.yaml, or Movefile) to define environments and connection settings.

    When Wordmove searches for a Movefile, it looks in the current directory. If not found, it will traverse up the directory tree until it finds one or reaches a directory containing a wp-config.php file or the root directory.

    The Movefile is parsed as YAML and supports ERB (Embedded Ruby) for dynamic configuration values.

  6. Use WP-CLI for SQL search-replace operations

    master

    Wordmove can use WP-CLI as a SQL adapter to perform search-replace operations. This adapter relies on the wp command being available in your system $PATH. It automatically handles the replacement of strings across all tables while skipping the guid column to prevent breaking WordPress post identity.

    To ensure the adapter works correctly, it looks for the WordPress installation path in the following order of precedence:

    1. A wp-cli.yml file located in your local path (containing a path key).
    2. The current path provided by wp cli param-dump --with-values.
    3. The local_path provided in your Wordmove configuration.
  7. Use the Wordmove CLI

    master

    Wordmove provides a command-line interface for managing WordPress data transfers between environments. You can initialize a new configuration, check your environment setup, list available environments, and perform pull or push operations.

    Core Commands

    • init: Generates a new movefile.yml configuration file.
    • doctor: Performs local configuration and environment checks to ensure everything is set up correctly.
    • list: Lists all configured environments and virtual hosts.
    • pull: Downloads WordPress data from a remote host to your local machine.
    • push: Uploads WordPress data from your local machine to a remote host.
    • --version or -v: Prints the current version of Wordmove.
  8. Verify Wordmove installation and environment

    master

    Before starting, ensure you have the necessary peer dependencies installed and available in your system $PATH.

    Mandatory Peer Dependencies:

    • mysql: Required for database operations.
    • mysqldump: Required for database operations.
    • wp-cli: Required by default (though configurable).
    • rsync: Required if using the SSH protocol.
    • lftp: Required if using the FTP protocol.

    Remote Server Requirements: Your remote server should have gzip, nice, mysql, and rsync installed.

    To check your local configuration and environment readiness, run:

    wordmove doctor
    wordmove doctor
  9. Configure SSH authentication

    master

    Wordmove supports SSH for secure file transfers and remote command execution.

    Best Practice: Password-less Authentication It is highly recommended to use SSH public key authentication instead of writing passwords in your movefile.yml. To use your SSH public key, simply omit the password field from the database section of your remote environment configuration.

    SSH Configuration Example:

    production:
      ssh:
        host: host
        user: user
      database:
        host: host
        # password field omitted to use SSH keys
  10. Configure FTP and SFTP

    master

    Wordmove supports FTP and SFTP protocols, though FTP support is considered legacy/discontinued. To use these, you must have lftp installed on your local machine.

    FTP Configuration

    • Use production.wordpress_path for the relative FTP path.
    • Use production.wordpress_absolute_path for the absolute FTP path.
    • To enable passive FTP, set production.ftp.passive: true.

    SFTP Configuration

    Since version 3.2.0, SFTP is fully supported. You can enable it by setting the production.ftp.scheme configuration key.

    Note: Remote hooks do not work when using the FTP protocol.

  11. Use environment variables in movefile.yml

    master

    To protect sensitive credentials and facilitate team sharing, you can use environment variables in your movefile.yml using ERB tags syntax: <%= ENV['VARIABLE_NAME'] %>.

    Setting up variables

    1. Using the shell:

    export PROD_DB_USER="username"
    export PROD_DB_PASS="password"

    2. Using a .env file: Create a .env file in the same directory as your movefile.yml:

    PROD_DB_USER="username"
    PROD_DB_PASS="password"

    Applying variables to movefile.yml

    production:
      database:
        user: "<%= ENV['PROD_DB_USER'] %>"
        password: "<%= ENV['PROD_DB_PASS'] %>"
    production:
      database:
        user: "<%= ENV['PROD_DB_USER'] %>"
        password: "<%= ENV['PROD_DB_PASS'] %>"