Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
### 1.1.0: February 21st, 2019
* Support for local development without a VM (Valet, etc). by passing `--local` at the end of the arguments

### 1.0.0: February 21st, 2019
* Initial release
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ $ ./sync.sh production staging
$ ./sync.sh staging production
```

### Local development without VM (Valet, etc.)

The `--local` flag can be passed at the end of the arguments to skip using WP-CLI aliases for development. This means that you can use the sync script on a local development setup such as Valet.

```sh
# Sync production down to development
$ ./sync.sh production development --local
```

## Troubleshooting

### Unable to connect to development
Expand Down
1 change: 1 addition & 0 deletions sync-kinsta.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

# Syncing Trellis & Bedrock-based WordPress environments with WP-CLI aliases (Kinsta version)
# Version 1.1.0
# Copyright (c) Ben Word

DEVDIR="web/app/uploads/"
Expand Down
48 changes: 38 additions & 10 deletions sync.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

# Syncing Trellis & Bedrock-based WordPress environments with WP-CLI aliases
# Version 1.1.0
# Copyright (c) Ben Word

DEVDIR="web/app/uploads/"
Expand All @@ -14,15 +15,20 @@ STAGSITE="https://staging.example.com"

FROM=$1
TO=$2
LOCAL=false

if [[ $3 == "--local" ]]; then
LOCAL=true
fi

bold=$(tput bold)
normal=$(tput sgr0)

case "$1-$2" in
production-development) DIR="down ⬇️ " FROMSITE=$PRODSITE; FROMDIR=$PRODDIR; TOSITE=$DEVSITE; TODIR=$DEVDIR; ;;
staging-development) DIR="down ⬇️ " FROMSITE=$STAGSITE; FROMDIR=$STAGDIR; TOSITE=$DEVSITE; TODIR=$DEVDIR; ;;
development-production) DIR="up ⬆️ " FROMSITE=$DEVSITE; FROMDIR=$DEVDIR; TOSITE=$PRODSITE; TODIR=$PRODDIR; ;;
development-staging) DIR="up ⬆️ " FROMSITE=$DEVSITE; FROMDIR=$DEVDIR; TOSITE=$STAGSITE; TODIR=$STAGDIR; ;;
production-development) DIR="down ⬇️ " FROMSITE=$PRODSITE; FROMDIR=$PRODDIR; TOSITE=$DEVSITE; TODIR=$DEVDIR; ;;
staging-development) DIR="down ⬇️ " FROMSITE=$STAGSITE; FROMDIR=$STAGDIR; TOSITE=$DEVSITE; TODIR=$DEVDIR; ;;
development-production) DIR="up ⬆️ " FROMSITE=$DEVSITE; FROMDIR=$DEVDIR; TOSITE=$PRODSITE; TODIR=$PRODDIR; ;;
development-staging) DIR="up ⬆️ " FROMSITE=$DEVSITE; FROMDIR=$DEVDIR; TOSITE=$STAGSITE; TODIR=$STAGDIR; ;;
production-staging) DIR="horizontally ↔️ "; FROMSITE=$PRODSITE; FROMDIR=$PRODDIR; TOSITE=$STAGSITE; TODIR=$STAGDIR; ;;
staging-production) DIR="horizontally ↔️ "; FROMSITE=$STAGSITE; FROMDIR=$STAGDIR; TOSITE=$PRODSITE; TODIR=$PRODDIR; ;;
*) echo "usage: $0 production development | staging development | development staging | development production | staging production | production staging" && exit 1 ;;
Expand All @@ -40,7 +46,12 @@ if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
# Make sure both environments are available before we continue
availfrom() {
local AVAILFROM
AVAILFROM=$(wp "@$FROM" option get home 2>&1)

if [[ "$LOCAL" = true && $FROM == "development" ]]; then
AVAILFROM=$(wp option get home 2>&1)
else
AVAILFROM=$(wp "@$FROM" option get home 2>&1)
fi
if [[ $AVAILFROM == *"Error"* ]]; then
echo "❌ Unable to connect to $FROM"
exit 1
Expand All @@ -52,7 +63,12 @@ if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then

availto() {
local AVAILTO
AVAILTO=$(wp "@$TO" option get home 2>&1)
if [[ "$LOCAL" = true && $TO == "development" ]]; then
AVAILTO=$(wp option get home 2>&1)
else
AVAILTO=$(wp "@$TO" option get home 2>&1)
fi

if [[ $AVAILTO == *"Error"* ]]; then
echo "❌ Unable to connect to $TO"
exit 1
Expand All @@ -64,10 +80,22 @@ if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
echo

# Export/import database, run search & replace
wp "@$TO" db export &&
wp "@$TO" db reset --yes &&
wp "@$FROM" db export - | wp "@$TO" db import - &&
wp "@$TO" search-replace "$FROMSITE" "$TOSITE" &&
if [[ "$LOCAL" = true && $TO == "development" ]]; then
wp db export &&
wp db reset --yes &&
wp "@$FROM" db export - | wp db import - &&
wp search-replace "$FROMSITE" "$TOSITE"
elif [[ "$LOCAL" = true && $FROM == "development" ]]; then
wp "@$TO" db export &&
wp "@$TO" db reset --yes &&
wp db export - | wp "@$TO" db import - &&
wp "@$TO" search-replace "$FROMSITE" "$TOSITE"
else
wp "@$TO" db export &&
wp "@$TO" db reset --yes &&
wp "@$FROM" db export - | wp "@$TO" db import - &&
wp "@$TO" search-replace "$FROMSITE" "$TOSITE"
fi

# Sync uploads directory
chmod -R 755 web/app/uploads/ &&
Expand Down