Skip to content

Instantly share code, notes, and snippets.

@MogulChris
Created February 27, 2019 02:32
Show Gist options
  • Save MogulChris/710c9d06ea7b1b014270f227cdb1bddc to your computer and use it in GitHub Desktop.
Save MogulChris/710c9d06ea7b1b014270f227cdb1bddc to your computer and use it in GitHub Desktop.
wprestore.sh
#!/bin/bash
# one argument: the directory of a wp-config.php file
wpconfig=$1/wp-config.php
if [ ! -f "$wpconfig" ]; then
echo "$wpconfig not found."
exit
fi
db=`sed -n -e "s/^define( *'DB_NAME', *'\([^']*\)'.*/\1/p" < $wpconfig`
if [ -z $db ]; then
echo "Database name not found in $wpconfig."
exit
fi
user=`sed -n -e "s/^define( *'DB_USER', *'\([^']*\)'.*/\1/p" < $wpconfig`
if [ -z $db ]; then
echo "Database user not found in $wpconfig."
exit
fi
pw=`sed -n -e "s/^define( *'DB_PASSWORD', *'\([^']*\)'.*/\1/p" < $wpconfig`
if [ -z $db ]; then
echo "Databaseabase credentials not found in $wpconfig."
exit
fi
mysql --user=$user --password="$pw" $db < sla_backup_database.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment