Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bash Script to change database using wp-cli
#!/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
@Stephen-Cronin

This comment has been minimized.

Copy link
Owner Author

Stephen-Cronin commented Jul 17, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.