Created
August 1, 2019 23:29
-
-
Save eksiscloud/4d04d7262967de857f37551e0d85a025 to your computer and use it in GitHub Desktop.
Syncing two wordpress databases using WP-CLI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
DEVDIR="web/app/uploads/" | |
DEVSITE="https://example.dev" | |
PRODDIR="[email protected]:/srv/www/example.com/shared/uploads/" | |
PRODSITE="https://example.com" | |
STAGDIR="[email protected]:/srv/www/example.com/shared/uploads/" | |
STAGSITE="https://staging.example.com" | |
FROM=$1 | |
TO=$2 | |
case "$1-$2" in | |
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; ;; | |
*) echo "usage: $0 development production | development staging | production development | production staging" && exit 1 ;; | |
esac | |
read -r -p "Would you really like to reset the $TO database and sync $DIR from $FROM? [y/N] " response | |
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then | |
cd ../ && | |
wp "@$TO" db export && | |
wp "@$FROM" db export - | wp "@$TO" db import - && | |
wp "@$TO" search-replace "$FROMSITE" "$TOSITE" && | |
rsync -az --progress "$FROMDIR" "$TODIR" | |
fi | |
Usage: | |
## USAGE | |
# ./sync.sh | |
# usage: ./sync.sh development production | development staging | production development | production staging | |
## EXAMPLES | |
# ./sync.sh development production | |
# ./sync.sh production development |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment