Last active
March 27, 2018 08:18
-
-
Save davemac/849573dd345f32a86d0b1ba2a23e2cd0 to your computer and use it in GitHub Desktop.
bash script to deploy a local WordPress database to an existing staging site
This file contains hidden or 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
# push a local WP database to an existing staging site | |
# uses current directory as theme path and ssh alias | |
pushstage() { | |
START=$(date +%s) | |
# make a backup of the current local database | |
# get current directory name, used for database and URL | |
current=${PWD##*/} | |
cd ~/Sites/$current || return | |
# rsync the local database to staging site | |
wp db export $current.sql | |
rsync $current.sql $current-s:~/ | |
# make a backup of the staging database | |
wp @stage db export backup.sql | |
# reset the staging database | |
wp @stage db reset --yes | |
# import our rsynced local database and update URLs | |
wp @stage db import $current.sql | |
wp @stage search-replace "$current.localhost" "$current.dmctest.com.au" --all-tables | |
# deactivate plugins that aren't needed | |
wp @stage plugin deactivate debug-bar query-monitor acf-theme-code-pro wordpress-seo | |
# Discourage search engines from indexing this site | |
wp @stage option update blog_public 0 | |
END=$(date +%s) | |
DIFF=$(( $END - $START )) | |
echo -e "\n$current.localhost database now in use on $push_staging_url site.\nIt took $DIFF seconds, enjoy!\n" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment