Skip to content

Instantly share code, notes, and snippets.

@davemac
Last active Nov 15, 2017
Embed
What would you like to do?
wp-cli alias to push a local WP database to a staging site
# wp-cli alias to push a local WP database to a staging site
pushstage() {
START=$(date +%s)
# make a backup of the current local database
# get current directory name, used for database and URL
current=${PWD##*/}
wp db export $current.sql
# rsync the local database to staging site
rsync $current.sql $current-s:~/
# get the staging site URL for search replace
staging_full_url=$(wp @stage eval '$full_url=get_site_url(); echo $full_url;')
# make a backup of the staging database
wp @stage db export ../backup.sql
# reset the staging database
wp @stage db reset
# import our rsynced local database
wp @stage db import ../$current.sql
wp @stage search-replace "http://$current.localhost" "$staging_full_url" --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