Created
July 16, 2017 12:04
-
-
Save Stephen-Cronin/54089254111aa3c98e812e7bc36a7926 to your computer and use it in GitHub Desktop.
Bash Script to change database 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/bash | |
# Bash Script to change database using wp-cli | |
# Finds any previously exported .sql file and asks the user which one to change to (ie import) | |
# Recommended usage: Change your system to multiple ideal states and export the db for each (into main wp folder), then use this to switch between states. | |
# Example: I have db exports for empty installation, theme unit test data, woocommerce demo data, etc. | |
# Requires wp cli | |
# Needed on my Windows installation. YOU PROBABLY NEED TO REMOVE THIS IF NOT USING WINDOWS. | |
shopt -s expand_aliases | |
alias wp="wp.bat" | |
# Read the sql files in this folder and prompt user which one to restore | |
echo "" | |
echo "*****************************2" | |
echo "" | |
echo "Select database to restore" | |
echo "" | |
select opt in *.sql; | |
do | |
echo | |
if [ "${opt}" = "" ]; then | |
echo "ERROR: Please enter one of the numbers presented" | |
echo | |
exit | |
fi | |
case $opt in | |
$opt) | |
echo "Dropping tables ..." | |
wp db reset --yes # | |
echo "Restoring $opt ..." | |
wp db import $opt # | |
echo "Updating database" | |
wp core update-db # | |
break | |
;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Quick demo: https://youtu.be/f1vt0OgwQIo