Skip to content

Instantly share code, notes, and snippets.

@davemac
Last active March 3, 2022 13:51
Show Gist options
  • Save davemac/02b15a021c6eb8972096fa2ee5eacee5 to your computer and use it in GitHub Desktop.
Save davemac/02b15a021c6eb8972096fa2ee5eacee5 to your computer and use it in GitHub Desktop.

Revisions

  1. davemac renamed this gist Apr 4, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. davemac created this gist Mar 15, 2019.
    32 changes: 32 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    # 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

    cd ~/Sites/$current/wp-content/themes/$current
    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"
    }