2017 © Pedro Peláez
 

project wpsh

Wordpress sync commandline tool

image

gwa/wpsh

Wordpress sync commandline tool

  • Wednesday, January 11, 2017
  • by gwa
  • Repository
  • 1 Watchers
  • 3 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 3 Open issues
  • 3 Versions
  • 9 % Grown

The README.md

wpsh

A command line tool for local WordPress development., (*1)

Introduction

wpsh is a command line tool we use to sync the database and uploaded files from a remote (PRODUCTION) WordPress install to a local (DEVELOPMENT) install., (*2)

It was inspired by Drupal's drush tool., (*3)

Prerequisites

You will need:, (*4)

  • composer installed locally (for installation).
  • mysql needs to be installed remotely.
  • mysql and rsync need to be installed locally and in your path.
  • SSH access to the remote server.

Installation

Install globally using composer., (*5)

$ composer global require gwa/wpsh

Test that wpsh is installed:, (*6)

$ wpsh

You should see some usage help output., (*7)

Setup

Aliases

Site "aliases" contain the configuration for a site, either remote or local. wpsh looks for site aliases in ~/.wpsh., (*8)

First create the directory in your HOME directory., (*9)

$ mkdir ~/.wpsh

Create a file called in ~/.wpsh called alias.[mysite].php., (*10)

mysite can contain alphanumeric characters, hyphens and periods., (*11)

<?php
// File: ~/.wpsh/alias.mysite.php
return [
  // The production server
  //
  '@mysite.prod' => [
    // SSH configuration
    'remote' => [
      'host'     => '123.255.12.123',
      'user'     => 'username',
      // Path to a SSH key file
      // 'identity' => '~/.ssh/custom_rsa',
    ],

    // Absolute paths
    'path' => [
      // The base directory
      'base'    => '/var/www/mysite',
      // Path to a custom MySQL cnf file
      'cnf'     => '~/mysql_cnf/mysite.cnf',
      // Path to a custom wp dir, relative to base
      // 'wp' => '',
      // Path to a custom uploads dir, relative to base
      // 'uploads' => 'wp-content/uploads',
    ],

    // Database settings
    'db' => [
      // Name of the database
      'database' => 'dbname'
    ],

    // Other settings
    'settings' => [
      'siteurl' => 'http://www.example.com',
      // Set a custom `home` path. Defaults to siteurl.
      // 'home' => 'http://www.example.com/wp',
    ]
  ],

  // The local development copy
  // Settings as above, but without `remote`
  //
  '@mysite.local' => [
    'path' => [
      'base'    => '/path/local/server/wordpress',
    ],

    'db' => [
      'database' => 'dbname',
    ],

    'settings' => [
      'siteurl' => 'http://mysite.local',
    ]
  ],
];

MySQL cnf files

We use cnf files to store MySQL credentials., (*12)

You can save these in one of the default paths (see MySQL docs), or in a custom path that is defined in the site alias' cnf path., (*13)

Example:, (*14)

[client]
user=mysqluser
password="pa$$word"
host=127.0.0.1
port=3306

Usage

The following commands are available., (*15)

sa

Lists available aliases., (*16)

$ wpsh sa

mysqldump

Creates a mysql dump file., (*17)

$ wpsh mysqldump [@alias] > /path/to/outfile.sql

mysqlsync

Syncs DB from @alias1 to @alias2., (*18)

Updates settings and URLs in posts with the local settings and URLs., (*19)

$ wpsh mysqlsync [@alias1] [@alias2]

rsync

Syncs uploads from @alias1 to @alias2., (*20)

$ wpsh rsync [@alias1] [@alias2]

TODOs

[ ] Provide hook mechanism for custom scripts / MySQL queries to be executed after sync., (*21)

The Versions

11/01 2017

dev-master

9999999-dev

Wordpress sync commandline tool

  Sources   Download

MIT

The Requires

 

27/12 2016

v1.0.1

1.0.1.0

Wordpress sync commandline tool

  Sources   Download

MIT

The Requires

 

27/12 2016

v1.0

1.0.0.0

Wordpress sync commandline tool

  Sources   Download

The Requires