├── LICENSE ├── README.md ├── composer.json ├── scripts └── sync-all.sh ├── sync-db-from-dev.sh ├── sync-db-from-prod.sh └── wp-cli.yml /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Jasper Frumau 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Trellis Sync 2 | This is a repository for the Trellis Database and Uploads Folder Synchronisation scripts and WP CLI Aliases. Two scripts have been added here. The database backup script or `sync-db-from-prod.sh` to synch the production database with the one on the local server and `sync-all.sh` to synchronize both the database and uploads folder. 3 | 4 | ## File location and changes 5 | 6 | Make sure you change the domain in both the shell script and your wp-cli.yaml files. For using the `sync-db-from-prod.sh` script it should be placed in the Wordpress root. For using the `sync-all.sh` it is setup to be run from `site/scripts/`. Or at least it is setup from a subdirectory inside your WordPress root or site folder. 7 | 8 | ## Database Sync (Production -> Dev) 9 | The Database sync script `sync-db-from-prod.sh` and aliases setup has been created by **Raquelle**. See [Roots Blog post](https://roots.io/leveraging-wp-cli-aliases-in-your-wordpress-development-workflow/). It is set up to sync the database from production and update the one on development or on the local server. 10 | 11 | ## Sync All 12 | 13 | The Sync All script `sync-all.sh` which can be used to synchronize the uploads folder and database has been created by **Ben Word** and thread post where he added can be found at [Roots Discourse]( https://discourse.roots.io/t/leveraging-wp-cli-aliases-in-your-wordpress-development-workflow/8414/12) . It will work for synching to and from production to local and to and from staging to local. It is located in the scripts folder, but will work from any sub directory in your WordPress root which often tends to be site witha standard Trellis setup with Bedrock. 14 | 15 | ## Installation 16 | 17 | Installation can be done using `composer require trellis-sync/trellis-sync`. This is still not fully tested so do make a backup first! 18 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "trellis-sync/trellis-sync", 3 | "type": "script", 4 | "description": "Synchronization Tool for Trellis", 5 | "keywords": ["sync","backup", "wp-cli"], 6 | "homepage": "https://github.com/jasperf/trellis-sync", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Jasper Frumau", 11 | "email": "jasper@imagewize.com", 12 | "homepage": "https://imagewize.com", 13 | "role": "Developer" 14 | } 15 | ], 16 | "require": { 17 | "php": ">=5.6.0" 18 | }, 19 | "autoload": { 20 | "psr-0": { 21 | "Trellis Sync": "src" 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /scripts/sync-all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DEVDIR="web/app/uploads/" 4 | DEVSITE="example.dev" 5 | 6 | PRODDIR="web@example.com:/srv/www/example.com/current/web/app/uploads/" 7 | PRODSITE="example.com" 8 | 9 | STAGDIR="web@staging.example.com:/srv/www/example.com/current/web/app/uploads/" 10 | STAGSITE="staging.example.com" 11 | 12 | FROM=$1 13 | TO=$2 14 | 15 | case "$1-$2" in 16 | dev-prod) DIR="up"; FROMSITE=$DEVSITE; FROMDIR=$DEVDIR; TOSITE=$PRODSITE; TODIR=$PRODDIR; ;; 17 | dev-stage) DIR="up" FROMSITE=$DEVSITE; FROMDIR=$DEVDIR; TOSITE=$STAGSITE; TODIR=$STAGDIR; ;; 18 | prod-dev) DIR="down" FROMSITE=$PRODSITE; FROMDIR=$PRODDIR; TOSITE=$DEVSITE; TODIR=$DEVDIR; ;; 19 | stage-dev) DIR="down" FROMSITE=$STAGSITE; FROMDIR=$STAGDIR; TOSITE=$DEVSITE; TODIR=$DEVDIR; ;; 20 | *) echo "usage: $0 dev prod | dev stage | prod dev | prod stage" && exit 1 ;; 21 | esac 22 | 23 | read -r -p "Reset the $TO database and sync $DIR from $FROM? [y/N] " response 24 | read -r -p "Sync the uploads folder? [y/N] " uploads 25 | 26 | cd ../ && 27 | if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then 28 | wp "@$TO" db export $TO-backup.sql && 29 | wp "@$TO" db reset --yes && 30 | wp "@$FROM" db export $FROM-backup.sql && 31 | if $(wp "@$FROM" core is-installed --network); then 32 | wp "@$FROM" search-replace --url=$FROMSITE $FROMSITE $TOSITE --skip-columns=guid --network --export | wp "@$TO" db import - 33 | else 34 | wp "@$FROM" search-replace --url=$FROMSITE $FROMSITE $TOSITE --skip-columns=guid --export | wp "@$TO" db import - 35 | fi 36 | fi 37 | if [[ "$uploads" =~ ^([yY][eE][sS]|[yY])$ ]]; then 38 | rsync -L -az --progress "$FROMDIR" "$TODIR" 39 | fi 40 | -------------------------------------------------------------------------------- /sync-db-from-dev.sh: -------------------------------------------------------------------------------- 1 | # sync-db-from-dev.sh 2 | read -r -p "Do you solemnly swear that you have had fewer than 2 alcoholic beverages in the last hour and that you would really like to reset your production database and pull the latest from development? [y/N] " response 3 | if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]] 4 | then 5 | wp @production db reset --yes 6 | wp @development db export -> sql-dump-development.sql 7 | wp @production db import sql-dump-development.sql 8 | wp @production search-replace https://imagewize.dev https://imagewize.nl --skip-columns=guid 9 | else 10 | exit 0 11 | fi 12 | -------------------------------------------------------------------------------- /sync-db-from-prod.sh: -------------------------------------------------------------------------------- 1 | # sync-db-from-prod.sh 2 | read -r -p "Do you solemnly swear that you have had fewer than 2 alcoholic beverages in the last hour and that you would really like to reset your development database and pull the latest from production? [y/N] " response 3 | if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]] 4 | then 5 | wp @development db reset --yes 6 | wp @production db export -> sql-dump-production.sql 7 | wp @development db import sql-dump-production.sql 8 | wp @development search-replace https://imagewize.nl http://imagewizenl.dev --skip-columns=guid 9 | else 10 | exit 0 11 | fi 12 | -------------------------------------------------------------------------------- /wp-cli.yml: -------------------------------------------------------------------------------- 1 | path: web/wp 2 | 3 | @production: 4 | ssh: web@example.com/srv/www/example.com/current 5 | 6 | @development: 7 | ssh: vagrant@example.dev/srv/www/example.com/current 8 | --------------------------------------------------------------------------------